]> granicus.if.org Git - sudo/commitdiff
Avoid using exiting allocators in the front end.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 17 Jun 2015 23:00:54 +0000 (17:00 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 17 Jun 2015 23:00:54 +0000 (17:00 -0600)
19 files changed:
plugins/sudoers/Makefile.in
src/Makefile.in
src/conversation.c
src/env_hooks.c
src/exec.c
src/exec_common.c
src/exec_pty.c
src/hooks.c
src/load_plugins.c
src/net_ifs.c
src/parse_args.c
src/preserve_fds.c
src/regress/ttyname/check_ttyname.c
src/selinux.c
src/sesh.c
src/sudo.c
src/sudo.h
src/sudo_edit.c
src/ttyname.c

index 8bc9c0a3d27d5c6943031298adbb36e068dbb13d..30ef2cace7ed027c84d3203c2eb15a878b9444d4 100644 (file)
@@ -796,8 +796,8 @@ match_addr.lo: $(srcdir)/match_addr.c $(devdir)/def_data.h \
        $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/match_addr.c
 match_addr.o: match_addr.lo
 net_ifs.o: $(top_srcdir)/src/net_ifs.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
            $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
            $(top_builddir)/config.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(top_srcdir)/src/net_ifs.c
index 791993026dccdfc2e380c3ad790d66c967c2819e..a8b30d247ca49af410b2488d63dfd1065d7a75d6 100644 (file)
@@ -225,169 +225,165 @@ cleandir: realclean
 
 # Autogenerated dependencies, do not modify
 check_ttyname.o: $(srcdir)/regress/ttyname/check_ttyname.c \
-                 $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-                 $(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
-                 $(incdir)/sudo_fatal.h $(incdir)/sudo_queue.h \
-                 $(incdir)/sudo_util.h $(top_builddir)/config.h
+                 $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+                 $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+                 $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
+                 $(top_builddir)/config.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/ttyname/check_ttyname.c
 conversation.o: $(srcdir)/conversation.c $(incdir)/compat/stdbool.h \
-                $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-                $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-                $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-                $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h \
-                $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+                $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+                $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+                $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
+                $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
                 $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
                 $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/conversation.c
 env_hooks.o: $(srcdir)/env_hooks.c $(incdir)/compat/stdbool.h \
-             $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-             $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_dso.h \
+             $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+             $(incdir)/sudo_debug.h $(incdir)/sudo_dso.h \
              $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
              $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h \
              $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
              $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/env_hooks.c
-exec.o: $(srcdir)/exec.c $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-        $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-        $(incdir)/sudo_event.h $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
+exec.o: $(srcdir)/exec.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+        $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_event.h \
+        $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
         $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
         $(srcdir)/sudo.h $(srcdir)/sudo_exec.h $(srcdir)/sudo_plugin_int.h \
         $(top_builddir)/config.h $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/exec.c
 exec_common.o: $(srcdir)/exec_common.c $(incdir)/compat/stdbool.h \
-               $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-               $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-               $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-               $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
-               $(srcdir)/sudo_exec.h $(top_builddir)/config.h \
-               $(top_builddir)/pathnames.h
+               $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+               $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+               $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
+               $(incdir)/sudo_util.h $(srcdir)/sudo.h $(srcdir)/sudo_exec.h \
+               $(top_builddir)/config.h $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/exec_common.c
 exec_pty.o: $(srcdir)/exec_pty.c $(incdir)/compat/stdbool.h \
-            $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-            $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-            $(incdir)/sudo_event.h $(incdir)/sudo_fatal.h \
-            $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
-            $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
-            $(srcdir)/sudo_exec.h $(srcdir)/sudo_plugin_int.h \
-            $(top_builddir)/config.h $(top_builddir)/pathnames.h
+            $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+            $(incdir)/sudo_debug.h $(incdir)/sudo_event.h \
+            $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
+            $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h \
+            $(incdir)/sudo_util.h $(srcdir)/sudo.h $(srcdir)/sudo_exec.h \
+            $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
+            $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/exec_pty.c
 get_pty.o: $(srcdir)/get_pty.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
            $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
            $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
            $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/get_pty.c
-hooks.o: $(srcdir)/hooks.c $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-         $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-         $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-         $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
-         $(srcdir)/sudo.h $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
+hooks.o: $(srcdir)/hooks.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+         $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+         $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
+         $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+         $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
          $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/hooks.c
 load_plugins.o: $(srcdir)/load_plugins.c $(incdir)/compat/stdbool.h \
-                $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-                $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-                $(incdir)/sudo_dso.h $(incdir)/sudo_fatal.h \
-                $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
-                $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+                $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+                $(incdir)/sudo_debug.h $(incdir)/sudo_dso.h \
+                $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
+                $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h \
+                $(incdir)/sudo_util.h $(srcdir)/sudo.h \
                 $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
                 $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/load_plugins.c
 net_ifs.o: $(srcdir)/net_ifs.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
            $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
            $(top_builddir)/config.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/net_ifs.c
 openbsd.o: $(srcdir)/openbsd.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
            $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
            $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
            $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/openbsd.c
 parse_args.o: $(srcdir)/parse_args.c $(incdir)/compat/getopt.h \
-              $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-              $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
-              $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
-              $(incdir)/sudo_gettext.h $(incdir)/sudo_lbuf.h \
-              $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
-              $(top_builddir)/config.h $(top_builddir)/pathnames.h \
-              ./sudo_usage.h
+              $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+              $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
+              $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
+              $(incdir)/sudo_lbuf.h $(incdir)/sudo_queue.h \
+              $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
+              $(top_builddir)/pathnames.h ./sudo_usage.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/parse_args.c
 preload.o: $(srcdir)/preload.c $(incdir)/sudo_compat.h $(incdir)/sudo_dso.h \
            $(incdir)/sudo_plugin.h $(top_builddir)/config.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/preload.c
 preserve_fds.o: $(srcdir)/preserve_fds.c $(incdir)/compat/stdbool.h \
-                $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-                $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-                $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-                $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+                $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+                $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+                $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
+                $(incdir)/sudo_util.h $(srcdir)/sudo.h \
                 $(top_builddir)/config.h $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/preserve_fds.c
 selinux.o: $(srcdir)/selinux.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
            $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
            $(incdir)/sudo_util.h $(srcdir)/sudo.h $(srcdir)/sudo_exec.h \
            $(top_builddir)/config.h $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/selinux.c
-sesh.o: $(srcdir)/sesh.c $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-        $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-        $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-        $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
-        $(srcdir)/sudo_exec.h $(top_builddir)/config.h
+sesh.o: $(srcdir)/sesh.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+        $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+        $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
+        $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo_exec.h \
+        $(top_builddir)/config.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/sesh.c
-signal.o: $(srcdir)/signal.c $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
+signal.o: $(srcdir)/signal.c $(incdir)/compat/stdbool.h \
           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
           $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
           $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
           $(top_builddir)/config.h $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/signal.c
 solaris.o: $(srcdir)/solaris.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_dso.h \
-           $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-           $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
-           $(top_builddir)/config.h $(top_builddir)/pathnames.h
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_dso.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
+           $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
+           $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/solaris.c
-sudo.o: $(srcdir)/sudo.c $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-        $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-        $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-        $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
-        $(srcdir)/sudo.h $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
+sudo.o: $(srcdir)/sudo.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+        $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+        $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
+        $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+        $(srcdir)/sudo_plugin_int.h $(top_builddir)/config.h \
         $(top_builddir)/pathnames.h ./sudo_usage.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/sudo.c
 sudo_edit.o: $(srcdir)/sudo_edit.c $(incdir)/compat/stdbool.h \
-             $(incdir)/compat/timespec.h $(incdir)/sudo_alloc.h \
-             $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
-             $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
-             $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
-             $(incdir)/sudo_util.h $(srcdir)/sudo.h $(srcdir)/sudo_exec.h \
-             $(top_builddir)/config.h $(top_builddir)/pathnames.h
+             $(incdir)/compat/timespec.h $(incdir)/sudo_compat.h \
+             $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
+             $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
+             $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+             $(srcdir)/sudo_exec.h $(top_builddir)/config.h \
+             $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/sudo_edit.c
 sudo_noexec.lo: $(srcdir)/sudo_noexec.c $(incdir)/sudo_compat.h \
                 $(top_builddir)/config.h
        $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/sudo_noexec.c
 tgetpass.o: $(srcdir)/tgetpass.c $(incdir)/compat/stdbool.h \
-            $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-            $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-            $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
-            $(incdir)/sudo_plugin.h $(incdir)/sudo_queue.h \
-            $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
-            $(top_builddir)/pathnames.h
+            $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+            $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+            $(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
+            $(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/sudo.h \
+            $(top_builddir)/config.h $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/tgetpass.c
 ttyname.o: $(srcdir)/ttyname.c $(incdir)/compat/stdbool.h \
-           $(incdir)/sudo_alloc.h $(incdir)/sudo_compat.h \
-           $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+           $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
+           $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
            $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
            $(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
            $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/ttyname.c
-utmp.o: $(srcdir)/utmp.c $(incdir)/compat/stdbool.h $(incdir)/sudo_alloc.h \
-        $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
-        $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
-        $(incdir)/sudo_util.h $(srcdir)/sudo.h $(srcdir)/sudo_exec.h \
-        $(top_builddir)/config.h $(top_builddir)/pathnames.h
+utmp.o: $(srcdir)/utmp.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+        $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
+        $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
+        $(srcdir)/sudo.h $(srcdir)/sudo_exec.h $(top_builddir)/config.h \
+        $(top_builddir)/pathnames.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/utmp.c
index f48deac89ea0349504f853ea8bdf4d5366cd09f2..b423a0e2ad358186869e439bd81ed2c1e5f35fb5 100644 (file)
@@ -80,7 +80,8 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
                pass = tgetpass(msg->msg, msg->timeout, flags);
                if (pass == NULL)
                    goto err;
-               repl->reply = sudo_estrdup(pass);
+               if ((repl->reply = strdup(pass)) == NULL)
+                   sudo_fatalx_nodebug(U_("unable to allocate memory"));
                memset_s(pass, SUDO_CONV_REPL_MAX, 0, strlen(pass));
                break;
            case SUDO_CONV_INFO_MSG:
index e4803507b866ef4f7174511636c07f7cbb567b84..bb250b50597a89defa77b15043bd64248e5a0f70 100644 (file)
@@ -115,7 +115,9 @@ rpl_putenv(PUTENV_CONST char *string)
     /* Append at the end if not already found. */
     if (!found) {
        size_t env_len = (size_t)(ep - environ);
-       char **envp = sudo_ereallocarray(priv_environ, env_len + 2, sizeof(char *));
+       char **envp = reallocarray(priv_environ, env_len + 2, sizeof(char *));
+       if (envp == NULL)
+           return -1;
        if (environ != priv_environ)
            memcpy(envp, environ, env_len * sizeof(char *));
        envp[env_len++] = (char *)string;
@@ -190,7 +192,11 @@ rpl_setenv(const char *var, const char *val, int overwrite)
        free(envstr);
        return 0;
     }
-    return rpl_putenv(envstr);
+    if (rpl_putenv(envstr) == -1) {
+       free(envstr);
+       return -1;
+    }
+    return 0;
 }
 
 typedef int (*sudo_fn_setenv_t)(const char *, const char *, int);
index d911d7bb35cec5e64a1525be259dfc95c4ad28c8..30a47d39298fa0662d30d9d37d1bc20a7e2f428f 100644 (file)
@@ -527,7 +527,7 @@ sudo_execute(struct command_details *details, struct command_status *cstat)
     sudo_ev_free(signal_event);
     sudo_ev_free(backchannel_event);
     TAILQ_FOREACH_SAFE(sigfwd, &sigfwd_list, entries, sigfwd_next) {
-       sudo_efree(sigfwd);
+       free(sigfwd);
     }
     TAILQ_INIT(&sigfwd_list);
 done:
@@ -833,7 +833,7 @@ forward_signals(int sock, int what, void *v)
            nsent = send(sock, &cstat, sizeof(cstat), 0);
        } while (nsent == -1 && errno == EINTR);
        TAILQ_REMOVE(&sigfwd_list, sigfwd, entries);
-       sudo_efree(sigfwd);
+       free(sigfwd);
        if (nsent != sizeof(cstat)) {
            if (errno == EPIPE) {
                struct sigforward *sigfwd_next;
@@ -841,7 +841,7 @@ forward_signals(int sock, int what, void *v)
                    "broken pipe writing to child over backchannel");
                /* Other end of socket gone, empty out sigfwd_list. */
                TAILQ_FOREACH_SAFE(sigfwd, &sigfwd_list, entries, sigfwd_next) {
-                   sudo_efree(sigfwd);
+                   free(sigfwd);
                }
                TAILQ_INIT(&sigfwd_list);
                /* XXX - child (monitor) is dead, we should exit too? */
@@ -869,7 +869,8 @@ schedule_signal(struct sudo_event_base *evbase, int signo)
        snprintf(signame, sizeof(signame), "%d", signo);
     sudo_debug_printf(SUDO_DEBUG_DIAG, "scheduled SIG%s for child", signame);
 
-    sigfwd = sudo_ecalloc(1, sizeof(*sigfwd));
+    if ((sigfwd = calloc(1, sizeof(*sigfwd))) == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
     sigfwd->signo = signo;
     TAILQ_INSERT_TAIL(&sigfwd_list, sigfwd, entries);
 
index d126cd664db2451c7a1c209de2d92a193af2600a..d2162183c2cc023a81360583a0598dfb812e81aa 100644 (file)
@@ -100,7 +100,9 @@ disable_execute(char *const envp[])
     if (!enabled)
        env_size++;
 #endif
-    nenvp = sudo_emallocarray(env_size, sizeof(*envp));
+    nenvp = reallocarray(NULL, env_size, sizeof(*envp));
+    if (nenvp == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
     memcpy(nenvp, envp, env_len * sizeof(*envp));
     nenvp[env_len] = NULL;
 
@@ -112,11 +114,14 @@ disable_execute(char *const envp[])
        preload = sudo_new_key_val(RTLD_PRELOAD_VAR, sudo_conf_noexec_path());
 # endif
        if (preload == NULL)
-           sudo_fatal(NULL);
+           sudo_fatalx(U_("unable to allocate memory"));
        nenvp[env_len++] = preload;
        nenvp[env_len] = NULL;
     } else {
-       sudo_easprintf(&preload, "%s=%s%s%s", RTLD_PRELOAD_VAR, sudo_conf_noexec_path(), RTLD_PRELOAD_DELIM, nenvp[preload_idx]);
+       int len = asprintf(&preload, "%s=%s%s%s", RTLD_PRELOAD_VAR,
+           sudo_conf_noexec_path(), RTLD_PRELOAD_DELIM, nenvp[preload_idx]);
+       if (len == -1)
+           sudo_fatalx(U_("unable to allocate memory"));
        nenvp[preload_idx] = preload;
     }
 # ifdef RTLD_PRELOAD_ENABLE_VAR
@@ -151,12 +156,14 @@ sudo_execve(const char *path, char *const argv[], char *const envp[], bool noexe
 
        for (argc = 0; argv[argc] != NULL; argc++)
            continue;
-       nargv = sudo_emallocarray(argc + 2, sizeof(char *));
-       nargv[0] = "sh";
-       nargv[1] = (char *)path;
-       memcpy(nargv + 2, argv + 1, argc * sizeof(char *));
-       execve(_PATH_SUDO_BSHELL, nargv, envp);
-       sudo_efree(nargv);
+       nargv = reallocarray(NULL, argc + 2, sizeof(char *));
+       if (nargv != NULL) {
+           nargv[0] = "sh";
+           nargv[1] = (char *)path;
+           memcpy(nargv + 2, argv + 1, argc * sizeof(char *));
+           execve(_PATH_SUDO_BSHELL, nargv, envp);
+           free(nargv);
+       }
     }
     return -1;
 }
index 73c3517e59ff0bdbbb89c57970f404ebb5ed616e..06b196f09c83fc3fc90e7240a824c984a99d3486 100644 (file)
@@ -695,7 +695,8 @@ io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct i
        (void) fcntl(wfd, F_SETFL, n | O_NONBLOCK);
 
     /* Allocate and add to head of list. */
-    iob = sudo_emalloc(sizeof(*iob));
+    if ((iob = malloc(sizeof(*iob))) == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
     iob->revent = sudo_ev_alloc(rfd, SUDO_EV_READ, io_callback, iob);
     iob->wevent = sudo_ev_alloc(wfd, SUDO_EV_WRITE, io_callback, iob);
     iob->len = 0;
@@ -703,7 +704,7 @@ io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct i
     iob->action = action;
     iob->buf[0] = '\0';
     if (iob->revent == NULL || iob->wevent == NULL)
-       sudo_fatal(NULL);
+       sudo_fatalx(U_("unable to allocate memory"));
     SLIST_INSERT_HEAD(head, iob, entries);
 
     debug_return;
@@ -907,7 +908,7 @@ pty_close(struct command_status *cstat)
     /* Free I/O buffers. */
     while ((iob = SLIST_FIRST(&iobufs)) != NULL) {
        SLIST_REMOVE_HEAD(&iobufs, entries);
-       sudo_efree(iob);
+       free(iob);
     }
 
     /* Restore terminal settings. */
index 63eac293045eaaee25491dcba8c4e3f3f2be6ea6..dd305a340a68a6dc5958f24e5dd6e5da4bbfcb4c 100644 (file)
@@ -35,6 +35,7 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
+#include <errno.h>
 
 #include "sudo.h"
 #include "sudo_plugin.h"
@@ -132,51 +133,54 @@ process_hooks_unsetenv(const char *name)
 }
 
 /* Hook registration internals. */
-static void
+static int
 register_hook_internal(struct sudo_hook_list *head,
     int (*hook_fn)(), void *closure)
 {
     struct sudo_hook_entry *hook;
     debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS)
 
-    hook = sudo_ecalloc(1, sizeof(*hook));
+    if ((hook = calloc(1, sizeof(*hook))) == NULL)
+       debug_return_int(-1);
     hook->u.generic_fn = hook_fn;
     hook->closure = closure;
     SLIST_INSERT_HEAD(head, hook, entries);
 
-    debug_return;
+    debug_return_int(0);
 }
 
 /* Register the specified hook. */
 int
 register_hook(struct sudo_hook *hook)
 {
-    int rval = 0;
+    int rval;
     debug_decl(register_hook, SUDO_DEBUG_HOOKS)
 
     if (SUDO_HOOK_VERSION_GET_MAJOR(hook->hook_version) != SUDO_HOOK_VERSION_MAJOR) {
        /* Major versions must match. */
+       errno = EINVAL;
        rval = -1;
     } else {
        switch (hook->hook_type) {
            case SUDO_HOOK_GETENV:
-               register_hook_internal(&sudo_hook_getenv_list, hook->hook_fn,
-                   hook->closure);
+               rval = register_hook_internal(&sudo_hook_getenv_list,
+                   hook->hook_fn, hook->closure);
                break;
            case SUDO_HOOK_PUTENV:
-               register_hook_internal(&sudo_hook_putenv_list, hook->hook_fn,
-                   hook->closure);
+               rval = register_hook_internal(&sudo_hook_putenv_list,
+                   hook->hook_fn, hook->closure);
                break;
            case SUDO_HOOK_SETENV:
-               register_hook_internal(&sudo_hook_setenv_list, hook->hook_fn,
-                   hook->closure);
+               rval = register_hook_internal(&sudo_hook_setenv_list,
+                   hook->hook_fn, hook->closure);
                break;
            case SUDO_HOOK_UNSETENV:
-               register_hook_internal(&sudo_hook_unsetenv_list, hook->hook_fn,
-                   hook->closure);
+               rval = register_hook_internal(&sudo_hook_unsetenv_list,
+                   hook->hook_fn, hook->closure);
                break;
            default:
                /* XXX - use define for unknown value */
+               errno = ENOTSUP;
                rval = 1;
                break;
        }
@@ -200,7 +204,7 @@ deregister_hook_internal(struct sudo_hook_list *head,
                SLIST_REMOVE_HEAD(head, entries);
            else
                SLIST_REMOVE_AFTER(prev, entries);
-           sudo_efree(hook);
+           free(hook);
            break;
        }
        prev = hook;
index 9a9e480c5dbd46795bcc0bc3681166db598636cc..169374c434ed9690dc625c3e45b9033596b1b3b0 100644 (file)
@@ -155,16 +155,15 @@ static bool
 sudo_load_plugin(struct plugin_container *policy_plugin,
     struct plugin_container_list *io_plugins, struct plugin_info *info)
 {
-    struct plugin_container *container;
+    struct plugin_container *container = NULL;
     struct generic_plugin *plugin;
     char path[PATH_MAX];
-    bool rval = false;
-    void *handle;
+    void *handle = NULL;
     debug_decl(sudo_load_plugin, SUDO_DEBUG_PLUGIN)
 
     /* Sanity check plugin and fill in path */
     if (!sudo_check_plugin(info, path, sizeof(path)))
-       goto done;
+       goto bad;
 
     /* Open plugin and map in symbol */
     handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
@@ -172,21 +171,21 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
        sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"),
            _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        sudo_warnx(U_("unable to load %s: %s"), path, sudo_dso_strerror());
-       goto done;
+       goto bad;
     }
     plugin = sudo_dso_findsym(handle, info->symbol_name);
     if (!plugin) {
        sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"),
            _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        sudo_warnx(U_("unable to find symbol `%s' in %s"), info->symbol_name, path);
-       goto done;
+       goto bad;
     }
 
     if (plugin->type != SUDO_POLICY_PLUGIN && plugin->type != SUDO_IO_PLUGIN) {
        sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"),
            _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        sudo_warnx(U_("unknown policy type %d found in %s"), plugin->type, path);
-       goto done;
+       goto bad;
     }
     if (SUDO_API_VERSION_GET_MAJOR(plugin->version) != SUDO_API_VERSION_MAJOR) {
        sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"),
@@ -194,25 +193,28 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
        sudo_warnx(U_("incompatible plugin major version %d (expected %d) found in %s"),
            SUDO_API_VERSION_GET_MAJOR(plugin->version),
            SUDO_API_VERSION_MAJOR, path);
-       goto done;
+       goto bad;
     }
     if (plugin->type == SUDO_POLICY_PLUGIN) {
-       if (policy_plugin->handle) {
+       if (policy_plugin->handle != NULL) {
            /* Ignore duplicate entries. */
            if (strcmp(policy_plugin->name, info->symbol_name) != 0) {
                sudo_warnx(U_("ignoring policy plugin `%s' in %s, line %d"),
                    info->symbol_name, _PATH_SUDO_CONF, info->lineno);
                sudo_warnx(U_("only a single policy plugin may be specified"));
-               goto done;
+               goto bad;
            }
            sudo_warnx(U_("ignoring duplicate policy plugin `%s' in %s, line %d"),
                info->symbol_name, _PATH_SUDO_CONF, info->lineno);
-           sudo_dso_unload(handle);
-           handle = NULL;
+           goto bad;
        }
        if (handle != NULL) {
            policy_plugin->handle = handle;
-           policy_plugin->path = sudo_estrdup(path);
+           policy_plugin->path = strdup(path);
+           if (policy_plugin->path == NULL) {
+               sudo_warnx(U_("unable to allocate memory"));
+               goto bad;
+           }
            policy_plugin->name = info->symbol_name;
            policy_plugin->options = info->options;
            policy_plugin->debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
@@ -231,9 +233,12 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
            }
        }
        if (handle != NULL) {
-           container = sudo_ecalloc(1, sizeof(*container));
+           container = calloc(1, sizeof(*container));
+           if (container == NULL || (container->path = strdup(path)) == NULL) {
+               sudo_warnx(U_("unable to allocate memory"));
+               goto bad;
+           }
            container->handle = handle;
-           container->path = sudo_estrdup(path);
            container->name = info->symbol_name;
            container->options = info->options;
            container->debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
@@ -247,18 +252,21 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
     info->symbol_name = NULL;
     info->options = NULL;
 
-    rval = true;
-done:
-    debug_return_bool(rval);
+    debug_return_bool(true);
+bad:
+    free(container);
+    if (handle != NULL)
+       sudo_dso_unload(handle);
+    debug_return_bool(false);
 }
 
 static void
 free_plugin_info(struct plugin_info *info)
 {
-    sudo_efree(info->path);
-    sudo_efree(info->options);
-    sudo_efree(info->symbol_name);
-    sudo_efree(info);
+    free(info->path);
+    free(info->options);
+    free(info->symbol_name);
+    free(info);
 }
 
 /*
@@ -290,23 +298,31 @@ sudo_load_plugins(struct plugin_container *policy_plugin,
      */
     if (policy_plugin->handle == NULL) {
        /* Default policy plugin */
-       info = sudo_ecalloc(1, sizeof(*info));
+       info = calloc(1, sizeof(*info));
+       if (info == NULL) {
+           sudo_warnx(U_("unable to allocate memory"));
+           goto done;
+       }
        info->symbol_name = "sudoers_policy";
        info->path = SUDOERS_PLUGIN;
        /* info->options = NULL; */
        rval = sudo_load_plugin(policy_plugin, io_plugins, info);
-       sudo_efree(info);
+       free(info);
        if (!rval)
            goto done;
 
        /* Default I/O plugin */
        if (TAILQ_EMPTY(io_plugins)) {
-           info = sudo_ecalloc(1, sizeof(*info));
+           info = calloc(1, sizeof(*info));
+           if (info == NULL) {
+               sudo_warnx(U_("unable to allocate memory"));
+               goto done;
+           }
            info->symbol_name = "sudoers_io";
            info->path = SUDOERS_PLUGIN;
            /* info->options = NULL; */
            rval = sudo_load_plugin(policy_plugin, io_plugins, info);
-           sudo_efree(info);
+           free(info);
            if (!rval)
                goto done;
        }
index 900b99e889497954a697fad4f119ad9ccc0d8b30..d9a80d7058fe06c6c026e711e56fbcccd61ccee7 100644 (file)
@@ -90,7 +90,6 @@ struct rtentry;
 #include "sudo_gettext.h"      /* must be included before sudo_compat.h */
 
 #include "sudo_compat.h"
-#include "sudo_alloc.h"
 #include "sudo_fatal.h"
 #include "sudo_conf.h"
 #include "sudo_debug.h"
@@ -111,7 +110,7 @@ struct rtentry;
 
 /*
  * Fill in the interfaces string with the machine's ip addresses and netmasks
- * and return the number of interfaces found.
+ * and return the number of interfaces found.  Returns -1 on error.
  */
 int
 get_net_ifs(char **addrinfo)
@@ -128,9 +127,12 @@ get_net_ifs(char **addrinfo)
     char *cp;
     debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
 
-    if (!sudo_conf_probe_interfaces() || getifaddrs(&ifaddrs) != 0)
+    if (!sudo_conf_probe_interfaces())
        debug_return_int(0);
 
+    if (getifaddrs(&ifaddrs) == -1)
+       debug_return_int(-1);
+
     /* Allocate space for the interfaces info string. */
     for (ifa = ifaddrs; ifa != NULL; ifa = ifa -> ifa_next) {
        /* Skip interfaces marked "down" and "loopback". */
@@ -150,7 +152,9 @@ get_net_ifs(char **addrinfo)
     if (num_interfaces == 0)
        debug_return_int(0);
     ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;
-    *addrinfo = cp = sudo_emalloc(ailen);
+    if ((cp = malloc(ailen)) == NULL)
+       debug_return_int(-1);
+    *addrinfo = cp;
 
     /* Store the IP addr/netmask pairs. */
     for (ifa = ifaddrs; ifa != NULL; ifa = ifa -> ifa_next) {
@@ -201,7 +205,7 @@ done:
 #ifdef HAVE_FREEIFADDRS
     freeifaddrs(ifaddrs);
 #else
-    sudo_efree(ifaddrs);
+    free(ifaddrs);
 #endif
     debug_return_int(num_interfaces);
 }
@@ -209,8 +213,8 @@ done:
 #elif defined(SIOCGIFCONF) && !defined(STUB_LOAD_INTERFACES)
 
 /*
- * Allocate and fill in the interfaces global variable with the
- * machine's ip addresses and netmasks.
+ * Fill in the interfaces string with the machine's ip addresses and netmasks
+ * and return the number of interfaces found.  Returns -1 on error.
  */
 int
 get_net_ifs(char **addrinfo)
@@ -233,13 +237,16 @@ get_net_ifs(char **addrinfo)
 
     sock = socket(AF_INET, SOCK_DGRAM, 0);
     if (sock < 0)
-       sudo_fatal(U_("unable to open socket"));
+       debug_return_int(-1);
 
     /*
      * Get interface configuration or return.
      */
     for (;;) {
-       ifconf_buf = sudo_emalloc(buflen);
+       if ((ifconf_buf = malloc(buflen)) == NULL) {
+           num_interfaces = -1;
+           goto done;
+       }
        ifconf = (struct ifconf *) ifconf_buf;
        ifconf->ifc_len = buflen - sizeof(struct ifconf);
        ifconf->ifc_buf = (caddr_t) (ifconf_buf + sizeof(struct ifconf));
@@ -257,14 +264,18 @@ get_net_ifs(char **addrinfo)
        if (ifconf->ifc_len + sizeof(struct ifreq) < buflen)
            break;
        buflen += BUFSIZ;
-       sudo_efree(ifconf_buf);
+       free(ifconf_buf);
     }
 
     /* Allocate space for the maximum number of interfaces that could exist. */
     if ((n = ifconf->ifc_len / sizeof(struct ifreq)) == 0)
-       debug_return_int(0);
+       goto done;
     ailen = n * 2 * INET6_ADDRSTRLEN;
-    *addrinfo = cp = sudo_emalloc(ailen);
+    if ((cp = malloc(ailen)) == NULL) {
+       num_interfaces = -1;
+       goto done;
+    }
+    *addrinfo = cp;
 
     /* For each interface, store the ip address and netmask. */
     for (i = 0; i < ifconf->ifc_len; ) {
@@ -333,7 +344,7 @@ get_net_ifs(char **addrinfo)
     }
 
 done:
-    sudo_efree(ifconf_buf);
+    free(ifconf_buf);
     (void) close(sock);
 
     debug_return_int(num_interfaces);
index f3d0aa2a5c70d26ef4546481e10417baf05ee164..21b53fc4865928bcd19e80ed1cd5e633678b56f3 100644 (file)
@@ -184,7 +184,9 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
     if (argc <= 0)
        usage(1);
 
-    env_add = sudo_emallocarray(env_size, sizeof(char *));
+    env_add = reallocarray(NULL, env_size, sizeof(char *));
+    if (env_add == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
 
     /* Pass progname to plugin so it can call initprogname() */
     progname = getprogname();
@@ -205,7 +207,8 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
     /* Set max_groups from sudo.conf. */
     i = sudo_conf_max_groups();
     if (i != -1) {
-       sudo_easprintf(&cp, "%d", i);
+       if (asprintf(&cp, "%d", i) == -1)
+           sudo_fatalx(U_("unable to allocate memory"));
        sudo_settings[ARG_MAX_GROUPS].value = cp;
     }
 
@@ -369,8 +372,13 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
            }
        } else if (!got_end_of_args && is_envar) {
            if (nenv == env_size - 2) {
+               char **tmp;
+
+               tmp = reallocarray(env_add, env_size, 2 * sizeof(char *));
+               if (tmp == NULL)
+                   sudo_fatalx(U_("unable to allocate memory"));
+               env_add = tmp;
                env_size *= 2;
-               env_add = sudo_ereallocarray(env_add, env_size, sizeof(char *));
            }
            env_add[nenv++] = argv[optind];
 
@@ -462,7 +470,9 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
            size_t cmnd_size = (size_t) (argv[argc - 1] - argv[0]) +
                strlen(argv[argc - 1]) + 1;
 
-           cmnd = dst = sudo_emallocarray(cmnd_size, 2);
+           cmnd = dst = reallocarray(NULL, cmnd_size, 2);
+           if (cmnd == NULL)
+               sudo_fatalx(U_("unable to allocate memory"));
            for (av = argv; *av != NULL; av++) {
                for (src = *av; *src != '\0'; src++) {
                    /* quote potential meta characters */
@@ -479,7 +489,9 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
            ac += 2; /* -c cmnd */
        }
 
-       av = sudo_emallocarray(ac + 1, sizeof(char *));
+       av = reallocarray(NULL, ac + 1, sizeof(char *));
+       if (av == NULL)
+           sudo_fatalx(U_("unable to allocate memory"));
        av[0] = (char *)user_details.shell; /* plugin may override shell */
        if (cmnd != NULL) {
            av[1] = "-c";
index 2a9994a3dc315063eafeb789d8dad447d2c08d06..818535f25b60c256e8126401fe2c0866e8939d07 100644 (file)
@@ -59,12 +59,14 @@ add_preserved_fd(struct preserved_fd_list *pfds, int fd)
     struct preserved_fd *pfd, *pfd_new;
     debug_decl(add_preserved_fd, SUDO_DEBUG_UTIL)
 
-    pfd_new = sudo_emalloc(sizeof(*pfd));
+    pfd_new = malloc(sizeof(*pfd));
+    if (pfd_new == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
     pfd_new->lowfd = fd;
     pfd_new->highfd = fd;
     pfd_new->flags = fcntl(fd, F_GETFD);
     if (pfd_new->flags == -1) {
-       sudo_efree(pfd_new);
+       free(pfd_new);
        debug_return_int(-1);
     }
 
@@ -73,7 +75,7 @@ add_preserved_fd(struct preserved_fd_list *pfds, int fd)
            /* already preserved */
            sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
                "fd %d already preserved", fd);
-           sudo_efree(pfd_new);
+           free(pfd_new);
            break;
        }
        if (fd < pfd->highfd) {
@@ -140,7 +142,9 @@ closefrom_except(int startfd, struct preserved_fd_list *pfds)
     }
 
     /* Create bitmap of preserved (relocated) fds.  */
-    fdsp = sudo_ecalloc(howmany(lastfd + 1, NFDBITS), sizeof(fd_mask));
+    fdsp = calloc(howmany(lastfd + 1, NFDBITS), sizeof(fd_mask));
+    if (fdsp == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
     TAILQ_FOREACH(pfd, pfds, entries) {
        FD_SET(pfd->lowfd, fdsp);
     }
index 9f1394d4f41e83b24db3751d9d2612aa52c4bb50..674189e66b354e3ae7ba76150314f45b26b36c05 100644 (file)
@@ -39,7 +39,6 @@
 #include <errno.h>
 
 #include "sudo_compat.h"
-#include "sudo_alloc.h"
 #include "sudo_fatal.h"
 #include "sudo_util.h"
 #include "sudo_debug.h"
@@ -89,6 +88,6 @@ main(int argc, char *argv[])
            tty_sudo ? tty_sudo : "none", tty_libc ? tty_libc : "none");
     }
 
-    sudo_efree(tty_sudo);
+    free(tty_sudo);
     exit(rval);
 }
index af3c2b06fbaafde976010022755086c403bf2d33..a017f4456f067ff23853b80eefd089b871ada484 100644 (file)
@@ -79,13 +79,15 @@ audit_role_change(const security_context_t old_context,
             sudo_fatal(U_("unable to open audit system"));
     } else {
        /* audit role change using the same format as newrole(1) */
-       sudo_easprintf(&message, "newrole: old-context=%s new-context=%s",
+       rc = asprintf(&message, "newrole: old-context=%s new-context=%s",
            old_context, new_context);
+       if (rc == -1)
+           sudo_fatalx(U_("unable to allocate memory"));
        rc = audit_log_user_message(au_fd, AUDIT_USER_ROLE_CHANGE,
            message, NULL, NULL, ttyn, result);
        if (rc <= 0)
            sudo_warn(U_("unable to send audit message"));
-       sudo_efree(message);
+       free(message);
        close(au_fd);
     }
 
@@ -286,7 +288,10 @@ get_exec_context(security_context_t old_context, const char *role, const char *t
     /*
      * Convert "context" back into a string and verify it.
      */
-    new_context = sudo_estrdup(context_str(context));
+    if ((new_context = strdup(context_str(context))) == NULL) {
+       sudo_warnx(U_("unable to allocate memory"));
+       goto bad;
+    }
     if (security_check_context(new_context) < 0) {
        sudo_warnx(U_("%s is not a valid context"), new_context);
        errno = EINVAL;
@@ -301,7 +306,7 @@ get_exec_context(security_context_t old_context, const char *role, const char *t
     debug_return_ptr(new_context);
 
 bad:
-    sudo_efree(typebuf);
+    free(typebuf);
     context_free(context);
     freecon(new_context);
     debug_return_ptr(NULL);
@@ -405,7 +410,11 @@ selinux_execve(const char *path, char *const argv[], char *const envp[],
      */
     for (argc = 0; argv[argc] != NULL; argc++)
        continue;
-    nargv = sudo_emallocarray(argc + 2, sizeof(char *));
+    nargv = reallocarray(NULL, argc + 2, sizeof(char *));
+    if (nargv == NULL) {
+       sudo_warnx(U_("unable to allocate memory"));
+       debug_return;
+    }
     if (noexec)
        nargv[0] = *argv[0] == '-' ? "-sesh-noexec" : "sesh-noexec";
     else
index ec10ec4e865b4811bf9d734c722bb705800ebfd3..3e2932c20ede982c16b772c8350741ee53890fac 100644 (file)
@@ -41,7 +41,6 @@
 #include "sudo_gettext.h"      /* must be included before sudo_compat.h */
 
 #include "sudo_compat.h"
-#include "sudo_alloc.h"
 #include "sudo_fatal.h"
 #include "sudo_conf.h"
 #include "sudo_debug.h"
@@ -98,7 +97,8 @@ main(int argc, char *argv[], char *envp[])
        /* Shift argv and make a copy of the command to execute. */
        argv++;
        argc--;
-       cmnd = sudo_estrdup(argv[0]);
+       if ((cmnd = strdup(argv[0])) == NULL)
+           sudo_fatalx(U_("unable to allocate memory"));
 
        /* If invoked as a login shell, modify argv[0] accordingly. */
        if (login_shell) {
index f509e4bebca9b8c5f39c50b1846fad9ce84087b0..261ce8fc69fada892875088351f361a850e62be7 100644 (file)
@@ -189,8 +189,8 @@ main(int argc, char *argv[], char *envp[])
     sudo_conf_read(NULL, SUDO_CONF_ALL & ~SUDO_CONF_DEBUG);
 
     /* Fill in user_info with user name, uid, cwd, etc. */
-    memset(&user_details, 0, sizeof(user_details));
-    user_info = get_user_info(&user_details);
+    if ((user_info = get_user_info(&user_details)) == NULL)
+       sudo_fatalx(U_("unable to allocate memory"));
 
     /* Disable core dumps if not enabled in sudo.conf. */
     disable_coredumps();
@@ -365,7 +365,11 @@ fill_group_list(struct user_details *ud, int system_maxgroups)
      */
     ud->ngroups = sudo_conf_max_groups();
     if (ud->ngroups > 0) {
-       ud->groups = sudo_emallocarray(ud->ngroups, sizeof(GETGROUPS_T));
+       ud->groups = reallocarray(NULL, ud->ngroups, sizeof(GETGROUPS_T));
+       if (ud->groups == NULL) {
+           sudo_warnx(U_("unable to allocate memory"));
+           goto done;
+       }
        /* No error on insufficient space if user specified max_groups. */
        (void)getgrouplist(ud->username, ud->gid, ud->groups, &ud->ngroups);
        rval = 0;
@@ -379,11 +383,16 @@ fill_group_list(struct user_details *ud, int system_maxgroups)
        ud->ngroups = system_maxgroups << 1;
        for (tries = 0; tries < 10 && rval == -1; tries++) {
            ud->ngroups <<= 1;
-           sudo_efree(ud->groups);
-           ud->groups = sudo_emallocarray(ud->ngroups, sizeof(GETGROUPS_T));
+           free(ud->groups);
+           ud->groups = reallocarray(NULL, ud->ngroups, sizeof(GETGROUPS_T));
+           if (ud->groups == NULL) {
+               sudo_warnx(U_("unable to allocate memory"));
+               goto done;
+           }
            rval = getgrouplist(ud->username, ud->gid, ud->groups, &ud->ngroups);
        }
     }
+done:
     debug_return_int(rval);
 }
 
@@ -395,6 +404,8 @@ get_user_groups(struct user_details *ud)
     int i, len, maxgroups, group_source;
     debug_decl(get_user_groups, SUDO_DEBUG_UTIL)
 
+    memset(ud, 0, sizeof(*ud));
+
     maxgroups = (int)sysconf(_SC_NGROUPS_MAX);
     if (maxgroups < 0)
        maxgroups = NGROUPS_MAX;
@@ -405,9 +416,11 @@ get_user_groups(struct user_details *ud)
        if ((ud->ngroups = getgroups(0, NULL)) > 0) {
            /* Use groups from kernel if not too many or source is static. */
            if (ud->ngroups < maxgroups || group_source == GROUP_SOURCE_STATIC) {
-               ud->groups = sudo_emallocarray(ud->ngroups, sizeof(GETGROUPS_T));
+               ud->groups = reallocarray(NULL, ud->ngroups, sizeof(GETGROUPS_T));
+               if (ud->groups == NULL)
+                   goto oom;
                if (getgroups(ud->ngroups, ud->groups) < 0) {
-                   sudo_efree(ud->groups);
+                   free(ud->groups);
                    ud->groups = NULL;
                }
            }
@@ -426,16 +439,20 @@ get_user_groups(struct user_details *ud)
      * Format group list as a comma-separated string of gids.
      */
     glsize = sizeof("groups=") - 1 + (ud->ngroups * (MAX_UID_T_LEN + 1));
-    gid_list = sudo_emalloc(glsize);
+    if ((gid_list = malloc(glsize)) == NULL)
+       goto oom;
     memcpy(gid_list, "groups=", sizeof("groups=") - 1);
     cp = gid_list + sizeof("groups=") - 1;
     for (i = 0; i < ud->ngroups; i++) {
-       /* XXX - check rval */
        len = snprintf(cp, glsize - (cp - gid_list), "%s%u",
            i ? "," : "", (unsigned int)ud->groups[i]);
+       if (len <= 0 || (size_t)len >= glsize - (cp - gid_list))
+           sudo_fatalx(U_("internal error, %s overflow"), __func__);
        cp += len;
     }
     debug_return_str(gid_list);
+oom:
+    sudo_fatalx(U_("unable to allocate memory"));
 }
 
 /*
@@ -451,7 +468,9 @@ get_user_info(struct user_details *ud)
     debug_decl(get_user_info, SUDO_DEBUG_UTIL)
 
     /* XXX - bound check number of entries */
-    user_info = sudo_emallocarray(32, sizeof(char *));
+    user_info = reallocarray(NULL, 32, sizeof(char *));
+    if (user_info == NULL)
+       goto bad;
 
     ud->pid = getpid();
     ud->ppid = getppid();
@@ -475,25 +494,34 @@ get_user_info(struct user_details *ud)
 
     user_info[i] = sudo_new_key_val("user", pw->pw_name);
     if (user_info[i] == NULL)
-       sudo_fatal(NULL);
+       goto bad;
     ud->username = user_info[i] + sizeof("user=") - 1;
 
     /* Stash user's shell for use with the -s flag; don't pass to plugin. */
     if ((ud->shell = getenv("SHELL")) == NULL || ud->shell[0] == '\0') {
        ud->shell = pw->pw_shell[0] ? pw->pw_shell : _PATH_SUDO_BSHELL;
     }
-    ud->shell = sudo_estrdup(ud->shell);
-
-    sudo_easprintf(&user_info[++i], "pid=%d", (int)ud->pid);
-    sudo_easprintf(&user_info[++i], "ppid=%d", (int)ud->ppid);
-    sudo_easprintf(&user_info[++i], "pgid=%d", (int)ud->pgid);
-    sudo_easprintf(&user_info[++i], "tcpgid=%d", (int)ud->tcpgid);
-    sudo_easprintf(&user_info[++i], "sid=%d", (int)ud->sid);
-
-    sudo_easprintf(&user_info[++i], "uid=%u", (unsigned int)ud->uid);
-    sudo_easprintf(&user_info[++i], "euid=%u", (unsigned int)ud->euid);
-    sudo_easprintf(&user_info[++i], "gid=%u", (unsigned int)ud->gid);
-    sudo_easprintf(&user_info[++i], "egid=%u", (unsigned int)ud->egid);
+    if ((ud->shell = strdup(ud->shell)) == NULL)
+       goto bad;
+
+    if (asprintf(&user_info[++i], "pid=%d", (int)ud->pid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "ppid=%d", (int)ud->ppid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "pgid=%d", (int)ud->pgid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "tcpgid=%d", (int)ud->tcpgid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "sid=%d", (int)ud->sid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "uid=%u", (unsigned int)ud->uid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "euid=%u", (unsigned int)ud->euid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "gid=%u", (unsigned int)ud->gid) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "egid=%u", (unsigned int)ud->egid) == -1)
+       goto bad;
 
     if ((cp = get_user_groups(ud)) != NULL)
        user_info[++i] = cp;
@@ -501,32 +529,43 @@ get_user_info(struct user_details *ud)
     if (getcwd(cwd, sizeof(cwd)) != NULL) {
        user_info[++i] = sudo_new_key_val("cwd", cwd);
        if (user_info[i] == NULL)
-           sudo_fatal(NULL);
+           goto bad;
        ud->cwd = user_info[i] + sizeof("cwd=") - 1;
     }
 
-    if ((cp = get_process_ttyname()) != NULL) {
+    if ((cp = get_process_ttyname()) == NULL) {
+       /* tty may not always be present */
+       if (errno == ENOMEM)
+           goto bad;
+    } else {
        user_info[++i] = sudo_new_key_val("tty", cp);
        if (user_info[i] == NULL)
-           sudo_fatal(NULL);
+           goto bad;
        ud->tty = user_info[i] + sizeof("tty=") - 1;
-       sudo_efree(cp);
+       free(cp);
     }
 
     cp = sudo_gethostname();
     user_info[++i] = sudo_new_key_val("host", cp ? cp : "localhost");
     if (user_info[i] == NULL)
-       sudo_fatal(NULL);
+       goto bad;
     ud->host = user_info[i] + sizeof("host=") - 1;
-    sudo_efree(cp);
+    free(cp);
 
     sudo_get_ttysize(&ud->ts_lines, &ud->ts_cols);
-    sudo_easprintf(&user_info[++i], "lines=%d", ud->ts_lines);
-    sudo_easprintf(&user_info[++i], "cols=%d", ud->ts_cols);
+    if (asprintf(&user_info[++i], "lines=%d", ud->ts_lines) == -1)
+       goto bad;
+    if (asprintf(&user_info[++i], "cols=%d", ud->ts_cols) == -1)
+       goto bad;
 
     user_info[++i] = NULL;
 
     debug_return_ptr(user_info);
+bad:
+    while (i--)
+       free(user_info[i]);
+    free(user_info);
+    debug_return_ptr(NULL);
 }
 
 /*
@@ -751,14 +790,14 @@ sudo_check_suid(const char *sudo)
        if (!qualified) {
            char *path = getenv_unhooked("PATH");
            if (path != NULL) {
-               int len;
-               char *cp, *colon;
-
-               cp = path = sudo_estrdup(path);
-               do {
-                   if ((colon = strchr(cp, ':')))
-                       *colon = '\0';
-                   len = snprintf(pathbuf, sizeof(pathbuf), "%s/%s", cp, sudo);
+               const char *cp, *ep;
+               const char *pathend = path + strlen(path);
+
+               for (cp = sudo_strsplit(path, pathend, ":", &ep); cp != NULL;
+                   cp = sudo_strsplit(NULL, pathend, ":", &ep)) {
+
+                   int len = snprintf(pathbuf, sizeof(pathbuf), "%.*s/%s",
+                       (int)(ep - cp), cp, sudo);
                    if (len <= 0 || (size_t)len >= sizeof(pathbuf))
                        continue;
                    if (access(pathbuf, X_OK) == 0) {
@@ -766,9 +805,7 @@ sudo_check_suid(const char *sudo)
                        qualified = true;
                        break;
                    }
-                   cp = colon + 1;
-               } while (colon);
-               sudo_efree(path);
+               }
            }
        }
 
@@ -1378,7 +1415,7 @@ iolog_unlink(struct plugin_container *plugin)
     }
     /* Remove from io_plugins list and free. */
     TAILQ_REMOVE(&io_plugins, plugin, entries);
-    sudo_efree(plugin);
+    free(plugin);
 
     debug_return;
 }
index 5da138ab16ba68f7d00a57a7804bb12180508533..7c35e6740e4c84c04db3f5fea31ef36168e45ce9 100644 (file)
@@ -33,7 +33,6 @@
 #include "sudo_gettext.h"      /* must be included before sudo_compat.h */
 
 #include "sudo_compat.h"
-#include "sudo_alloc.h"
 #include "sudo_fatal.h"
 #include "sudo_conf.h"
 #include "sudo_debug.h"
index d3cd22b51a24038270a8dc508729f80d1ae27172..a94b53d008c7d5e4be4c05bf060f974005b74cb9 100644 (file)
@@ -144,7 +144,7 @@ static int
 sudo_edit_mktemp(const char *ofile, char **tfile)
 {
     const char *cp, *suff;
-    int tfd;
+    int len, tfd;
     debug_decl(sudo_edit_mktemp, SUDO_DEBUG_EDIT)
 
     if ((cp = strrchr(ofile, '/')) != NULL)
@@ -153,11 +153,13 @@ sudo_edit_mktemp(const char *ofile, char **tfile)
        cp = ofile;
     suff = strrchr(cp, '.');
     if (suff != NULL) {
-       sudo_easprintf(tfile, "%s/%.*sXXXXXXXX%s", edit_tmpdir,
+       len = asprintf(tfile, "%s/%.*sXXXXXXXX%s", edit_tmpdir,
            (int)(size_t)(suff - cp), cp, suff);
     } else {
-       sudo_easprintf(tfile, "%s/%s.XXXXXXXX", edit_tmpdir, cp);
+       len = asprintf(tfile, "%s/%s.XXXXXXXX", edit_tmpdir, cp);
     }
+    if (len == -1)
+       sudo_fatalx(U_("unable to allocate memory"));
     tfd = mkstemps(*tfile, suff ? strlen(suff) : 0);
     sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
        "%s -> %s, fd %d", ofile, *tfile, tfd);
@@ -376,7 +378,11 @@ selinux_edit_create_tfiles(struct command_details *command_details,
     command_details->flags |= CD_SUDOEDIT_COPY;
     
     sesh_nargs = 3 + (nfiles * 2) + 1;
-    sesh_args = sesh_ap = sudo_emallocarray(sesh_nargs, sizeof(char *));
+    sesh_args = sesh_ap = reallocarray(NULL, sesh_nargs, sizeof(char *));
+    if (sesh_args == NULL) {
+       sudo_warnx(U_("unable to allocate memory"));
+       debug_return_int(-1);
+    }
     *sesh_ap++ = "sesh";
     *sesh_ap++ = "-e";
     *sesh_ap++ = "0";
@@ -397,8 +403,8 @@ selinux_edit_create_tfiles(struct command_details *command_details,
        tfd = sudo_edit_mktemp(ofile, &tfile);
        if (tfd == -1) {
            sudo_warn("mkstemps");
-           sudo_efree(tfile);
-           sudo_efree(sesh_args);
+           free(tfile);
+           free(sesh_args);
            debug_return_int(-1);
        }
        /* Helper will re-create temp file with proper security context. */
@@ -437,7 +443,7 @@ selinux_edit_create_tfiles(struct command_details *command_details,
     }
 
     /* Contents of tf will be freed by caller. */
-    sudo_efree(sesh_args);
+    free(sesh_args);
 
     return (nfiles);
 }
@@ -467,7 +473,11 @@ selinux_edit_copy_tfiles(struct command_details *command_details,
     command_details->flags |= CD_SUDOEDIT_COPY;
     
     sesh_nargs = 3 + (nfiles * 2) + 1;
-    sesh_args = sesh_ap = sudo_emallocarray(sesh_nargs, sizeof(char *));
+    sesh_args = sesh_ap = reallocarray(NULL, sesh_nargs, sizeof(char *));
+    if (sesh_args == NULL) {
+       sudo_warnx(U_("unable to allocate memory"));
+       debug_return_int(-1);
+    }
     *sesh_ap++ = "sesh";
     *sesh_ap++ = "-e";
     *sesh_ap++ = "1";
@@ -575,7 +585,11 @@ sudo_edit(struct command_details *command_details)
     }
 
     /* Copy editor files to temporaries. */
-    tf = sudo_ecalloc(nfiles, sizeof(*tf));
+    tf = calloc(nfiles, sizeof(*tf));
+    if (tf == NULL) {
+       sudo_warnx(U_("unable to allocate memory"));
+       goto cleanup;
+    }
 #ifdef HAVE_SELINUX
     if (ISSET(command_details->flags, CD_RBAC_ENABLED))
        nfiles = selinux_edit_create_tfiles(command_details, tf, files, nfiles);
@@ -591,7 +605,11 @@ sudo_edit(struct command_details *command_details)
      * to create a new argv.
      */
     nargc = editor_argc + nfiles;
-    nargv = sudo_emallocarray(nargc + 1, sizeof(char *));
+    nargv = reallocarray(NULL, nargc + 1, sizeof(char *));
+    if (nargv == NULL) {
+       sudo_warnx(U_("unable to allocate memory"));
+       goto cleanup;
+    }
     for (ac = 0; ac < editor_argc; ac++)
        nargv[ac] = command_details->argv[ac];
     for (i = 0; i < nfiles && ac < nargc; )
@@ -637,8 +655,8 @@ sudo_edit(struct command_details *command_details)
 #endif
        errors = sudo_edit_copy_tfiles(command_details, tf, nfiles, times);
 
-    sudo_efree(tf);
-    sudo_efree(nargv);
+    free(tf);
+    free(nargv);
     debug_return_int(errors ? 1 : rval);
 
 cleanup:
@@ -649,8 +667,8 @@ cleanup:
                unlink(tf[i].tfile);
        }
     }
-    sudo_efree(tf);
-    sudo_efree(nargv);
+    free(tf);
+    free(nargv);
     debug_return_int(1);
 }
 
index 28dc727e978051cf6e0efaac93dce690ab965e1a..bb6fa27fd1610c5b8ae9765b781dde2626d6adeb 100644 (file)
@@ -132,13 +132,17 @@ sudo_ttyname_dev(dev_t tdev)
        if (*dev != '/') {
            /* devname() doesn't use the /dev/ prefix, add one... */
            size_t len = sizeof(_PATH_DEV) + strlen(dev);
-           tty = sudo_emalloc(len);
-           strlcpy(tty, _PATH_DEV, len);
-           strlcat(tty, dev, len);
+           if ((tty = malloc(len)) != NULL) {
+               strlcpy(tty, _PATH_DEV, len);
+               strlcat(tty, dev, len);
+           }
        } else {
            /* Should not happen but just in case... */
-           tty = sudo_estrdup(dev);
+           tty = strdup(dev);
        }
+    } else {
+       /* Not all versions of devname() set errno. */
+       errno = ENOENT;
     }
     debug_return_str(tty);
 }
@@ -158,7 +162,7 @@ sudo_ttyname_dev(dev_t tdev)
 
     tty = _ttyname_dev(tdev, buf, sizeof(buf));
 
-    debug_return_str(sudo_estrdup(tty));
+    debug_return_str(tty ? strdup(tty) : NULL);
 }
 #elif defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__)
 /*
@@ -262,15 +266,24 @@ sudo_ttyname_scan(const char *dir, dev_t rdev, bool builtin)
            if (!builtin) {
                /* Add to list of subdirs to search. */
                if (num_subdirs + 1 > max_subdirs) {
+                   char **new_subdirs;
+
+                   new_subdirs = reallocarray(subdirs, max_subdirs + 64,
+                       sizeof(char *));
+                   if (new_subdirs == NULL)
+                       goto done;
+                   subdirs = new_subdirs;
                    max_subdirs += 64;
-                   subdirs = sudo_ereallocarray(subdirs, max_subdirs, sizeof(char *));
                }
-               subdirs[num_subdirs++] = sudo_estrdup(pathbuf);
+               subdirs[num_subdirs] = strdup(pathbuf);
+               if (subdirs[num_subdirs] == NULL)
+                   goto done;
+               num_subdirs++;
            }
            continue;
        }
        if (S_ISCHR(sb.st_mode) && sb.st_rdev == rdev) {
-           devname = sudo_estrdup(pathbuf);
+           devname = strdup(pathbuf);
            sudo_debug_printf(SUDO_DEBUG_INFO, "resolved dev %u as %s",
                (unsigned int)rdev, pathbuf);
            goto done;
@@ -285,8 +298,8 @@ done:
     if (d != NULL)
        closedir(d);
     for (i = 0; i < num_subdirs; i++)
-       sudo_efree(subdirs[i]);
-    sudo_efree(subdirs);
+       free(subdirs[i]);
+    free(subdirs);
     debug_return_str(devname);
 }
 
@@ -306,7 +319,7 @@ sudo_ttyname_dev(dev_t rdev)
     /*
      * First check search_devs for common tty devices.
      */
-    for (sd = search_devs; tty == NULL && (devname = *sd) != NULL; sd++) {
+    for (sd = search_devs; (devname = *sd) != NULL; sd++) {
        len = strlen(devname);
        if (devname[len - 1] == '/') {
            if (strcmp(devname, "/dev/pts/") == 0) {
@@ -314,19 +327,25 @@ sudo_ttyname_dev(dev_t rdev)
                (void)snprintf(buf, sizeof(buf), "%spts/%u", _PATH_DEV,
                    (unsigned int)minor(rdev));
                if (stat(buf, &sb) == 0) {
-                   if (S_ISCHR(sb.st_mode) && sb.st_rdev == rdev)
-                       tty = sudo_estrdup(buf);
+                   if (S_ISCHR(sb.st_mode) && sb.st_rdev == rdev) {
+                       tty = strdup(buf);
+                       goto done;
+                   }
                }
                sudo_debug_printf(SUDO_DEBUG_INFO, "comparing dev %u to %s: %s",
                    (unsigned int)rdev, buf, tty ? "yes" : "no");
            } else {
                /* Traverse directory */
                tty = sudo_ttyname_scan(devname, rdev, true);
+               if (tty != NULL || errno == ENOMEM)
+                   goto done;
            }
        } else {
            if (stat(devname, &sb) == 0) {
-               if (S_ISCHR(sb.st_mode) && sb.st_rdev == rdev)
-                   tty = sudo_estrdup(devname);
+               if (S_ISCHR(sb.st_mode) && sb.st_rdev == rdev) {
+                   tty = strdup(devname);
+                   goto done;
+               }
            }
        }
     }
@@ -334,9 +353,9 @@ sudo_ttyname_dev(dev_t rdev)
     /*
      * Not found?  Do a breadth-first traversal of /dev/.
      */
-    if (tty == NULL)
-       tty = sudo_ttyname_scan(_PATH_DEV, rdev, false);
+    tty = sudo_ttyname_scan(_PATH_DEV, rdev, false);
 
+done:
     debug_return_str(tty);
 }
 #endif
@@ -366,8 +385,14 @@ get_process_ttyname(void)
     mib[4] = sizeof(*ki_proc);
     mib[5] = 1;
     do {
+       struct sudo_kinfo_proc *kp;
+
        size += size / 10;
-       ki_proc = sudo_erealloc(ki_proc, size);
+       if ((kp = realloc(ki_proc, size)) == NULL) {
+           rc = -1;
+           break;              /* really out of memory. */
+       }
+       ki_proc = kp;
        rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);
     } while (rc == -1 && errno == ENOMEM);
     if (rc != -1) {
@@ -383,7 +408,7 @@ get_process_ttyname(void)
        sudo_debug_printf(SUDO_DEBUG_WARN,
            "unable to resolve tty via KERN_PROC: %s", strerror(errno));
     }
-    sudo_efree(ki_proc);
+    free(ki_proc);
 
     debug_return_str(tty);
 }
@@ -417,6 +442,10 @@ get_process_ttyname(void)
        }
     }
 
+    if (tty == NULL)
+       sudo_debug_printf(SUDO_DEBUG_WARN,
+           "unable to resolve tty via %s: %s", path, strerror(errno));
+
     debug_return_str(tty);
 }
 #elif defined(__linux__)
@@ -461,9 +490,13 @@ get_process_ttyname(void)
                }
            }
        }
-       sudo_efree(line);
+       free(line);
     }
 
+    if (tty == NULL)
+       sudo_debug_printf(SUDO_DEBUG_WARN,
+           "unable to resolve tty via %s: %s", path, strerror(errno));
+
     debug_return_str(tty);
 }
 #elif defined(HAVE_PSTAT_GETPROC)
@@ -490,6 +523,10 @@ get_process_ttyname(void)
                pstat.pst_term.psd_minor));
        }
     }
+    if (tty == NULL)
+       sudo_debug_printf(SUDO_DEBUG_WARN,
+           "unable to resolve tty via pstat: %s", strerror(errno));
+
     debug_return_str(tty);
 }
 #else
@@ -507,7 +544,12 @@ get_process_ttyname(void)
        if ((tty = ttyname(STDOUT_FILENO)) == NULL)
            tty = ttyname(STDERR_FILENO);
     }
+    if (tty == NULL) {
+       sudo_debug_printf(SUDO_DEBUG_WARN,
+           "unable to resolve tty via ttyname: %s", strerror(errno));
+       debug_return_str(NULL);
+    }
 
-    debug_return_str(sudo_estrdup(tty));
+    debug_return_str(strdup(tty));
 }
 #endif