]> granicus.if.org Git - sudo/commitdiff
Rename emalloc2() -> emallocarray() and erealloc3() -> ereallocarray().
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 22 Apr 2014 22:02:28 +0000 (16:02 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 22 Apr 2014 22:02:28 +0000 (16:02 -0600)
21 files changed:
common/alloc.c
common/event_poll.c
common/gidlist.c
common/sudo_conf.c
include/alloc.h
plugins/sudoers/auth/sia.c
plugins/sudoers/env.c
plugins/sudoers/group_plugin.c
plugins/sudoers/ldap.c
plugins/sudoers/pwutil_impl.c
plugins/sudoers/sssd.c
plugins/sudoers/sudoers.c
plugins/sudoers/sudoreplay.c
plugins/sudoers/visudo.c
src/env_hooks.c
src/exec_common.c
src/parse_args.c
src/selinux.c
src/sudo.c
src/sudo_edit.c
src/ttyname.c

index f9775a9cbd1e3526032a7b1cbb1dc9c06174a817..46a31135ea2c2512aa145353616fca3c1e7f9392 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999-2005, 2007, 2010-2013
+ * Copyright (c) 1999-2005, 2007, 2010-2014
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -58,7 +58,7 @@
 /*
  * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
  * could be signed (as it is on SunOS 4.x).  This just means that
- * emalloc2() and erealloc3() cannot allocate huge amounts on such a
+ * emallocarray() and ereallocarray() cannot allocate huge amounts on such a
  * platform but that is OK since sudo doesn't need to do so anyway.
  */
 #ifndef SIZE_MAX
@@ -87,18 +87,18 @@ emalloc(size_t size)
 }
 
 /*
- * emalloc2() allocates nmemb * size bytes and exits with an error
+ * emallocarray() allocates nmemb * size bytes and exits with an error
  * if overflow would occur or if the system malloc(3) fails.
  */
 void *
-emalloc2(size_t nmemb, size_t size)
+emallocarray(size_t nmemb, size_t size)
 {
     void *ptr;
 
     if (nmemb == 0 || size == 0)
-       fatalx_nodebug(_("internal error, tried to emalloc2(0)"));
+       fatalx_nodebug(_("internal error, tried to emallocarray(0)"));
     if (nmemb > SIZE_MAX / size)
-       fatalx_nodebug(_("internal error, %s overflow"), "emalloc2");
+       fatalx_nodebug(_("internal error, %s overflow"), "emallocarray");
 
     size *= nmemb;
     if ((ptr = malloc(size)) == NULL)
@@ -148,19 +148,19 @@ erealloc(void *ptr, size_t size)
 }
 
 /*
- * erealloc3() realloc(3)s nmemb * size bytes and exits with an error
+ * ereallocarray() realloc(3)s nmemb * size bytes and exits with an error
  * if overflow would occur or if the system malloc(3)/realloc(3) fails.
  * You can call erealloc() with a NULL pointer even if the system realloc(3)
  * does not support this.
  */
 void *
-erealloc3(void *ptr, size_t nmemb, size_t size)
+ereallocarray(void *ptr, size_t nmemb, size_t size)
 {
 
     if (nmemb == 0 || size == 0)
-       fatalx_nodebug(_("internal error, tried to erealloc3(0)"));
+       fatalx_nodebug(_("internal error, tried to ereallocarray(0)"));
     if (nmemb > SIZE_MAX / size)
-       fatalx_nodebug(_("internal error, %s overflow"), "erealloc3");
+       fatalx_nodebug(_("internal error, %s overflow"), "ereallocarray");
 
     size *= nmemb;
     ptr = ptr ? realloc(ptr, size) : malloc(size);
index 5cf35cca70868080882bd8fe8f4b41fc73b33e15..dfe1153f8a94cd5d3837f4712509a4e06fada987 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2013-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -60,7 +60,7 @@ sudo_ev_base_alloc_impl(struct sudo_event_base *base)
 
     base->pfd_high = -1;
     base->pfd_max = 32;
-    base->pfds = erealloc3(NULL, base->pfd_max, sizeof(struct pollfd));
+    base->pfds = ereallocarray(NULL, base->pfd_max, sizeof(struct pollfd));
     for (i = 0; i < base->pfd_max; i++) {
        base->pfds[i].fd = -1;
     }
@@ -87,7 +87,7 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev)
        int i;
        base->pfd_max <<= 1;
        base->pfds =
-           erealloc3(base->pfds, base->pfd_max, sizeof(struct pollfd));
+           ereallocarray(base->pfds, base->pfd_max, sizeof(struct pollfd));
        for (i = base->pfd_free; i < base->pfd_max; i++) {
            base->pfds[i].fd = -1;
        }
index 9d5d4805f9500eccb70b49a4b8bf4e87d8a00279..aaba612754e07a7f5358104b27378e111aa723f1 100644 (file)
@@ -67,7 +67,7 @@ parse_gid_list(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp)
        ngids++;
     /* Allocate and fill in array. */
     if (ngids != 0) {
-       gids = emalloc2(ngids, sizeof(GETGROUPS_T));
+       gids = emallocarray(ngids, sizeof(GETGROUPS_T));
        ngids = 0;
        if (basegid != NULL)
            gids[ngids++] = *basegid;
index 3d8d6bb579d7be0bc739898b0939e659e5218e58..d16bc1212fa7b235a49b8f13b6d4f9e1f4b93eab 100644 (file)
@@ -294,7 +294,7 @@ set_plugin(const char *entry, const char *conf_file)
            while (isblank((unsigned char)*ep))
                ep++;
        }
-       options = emalloc2(nopts + 1, sizeof(*options));
+       options = emallocarray(nopts + 1, sizeof(*options));
        /* Fill in options array, there is at least one element. */
        for (nopts = 0; (ep = strpbrk(cp, " \t")) != NULL; ) {
            options[nopts++] = estrndup(cp, (size_t)(ep - cp));
index 23fa6de7c7631a8248cf84d1f0dcd19c7a467bd1..f7c566c7c94712ae56507ce0f6a23104671dcbcd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010, 2012-1013
+ * Copyright (c) 2009-2010, 2012-1014
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -27,9 +27,9 @@ int    easprintf(char **, const char *, ...) __printflike(2, 3);
 int     evasprintf(char **, const char *, va_list) __printflike(2, 0);
 void   *ecalloc(size_t, size_t) __malloc_like;
 void   *emalloc(size_t) __malloc_like;
-void   *emalloc2(size_t, size_t) __malloc_like;
+void   *emallocarray(size_t, size_t) __malloc_like;
 void   *erealloc(void *, size_t);
-void   *erealloc3(void *, size_t, size_t);
+void   *ereallocarray(void *, size_t, size_t);
 void   *erecalloc(void *, size_t, size_t, size_t);
 char   *estrdup(const char *) __malloc_like;
 char   *estrndup(const char *, size_t) __malloc_like;
index c6050ca0ba8b2e5b8a0f116e0fa7ca2390f77f51..7de883f4182841521b96c65740687035bbfbf34f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999-2005, 2007, 2010-2013
+ * Copyright (c) 1999-2005, 2007, 2010-2014
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -96,7 +96,7 @@ sudo_sia_setup(struct passwd *pw, char **promptp, sudo_auth *auth)
 
     /* Rebuild argv for sia_ses_init() */
     sudo_argc = NewArgc + 1;
-    sudo_argv = emalloc2(sudo_argc + 1, sizeof(char *));
+    sudo_argv = emallocarray(sudo_argc + 1, sizeof(char *));
     sudo_argv[0] = "sudo";
     for (i = 0; i < NewArgc; i++)
        sudo_argv[i + 1] = NewArgv[i];
index 466469d5a820e1be093e29e3bb610e83d5e77d97..1265c293b8d6c16a4a26fddc3c19cdf2a1b0e3bd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2005, 2007-2013
+ * Copyright (c) 2000-2005, 2007-2014
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -60,8 +60,8 @@
 /*
  * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
  * could be signed (as it is on SunOS 4.x).  This just means that
- * emalloc2() and erealloc3() cannot allocate huge amounts on such a
- * platform but that is OK since sudo doesn't need to do so anyway.
+ * we cannot allocate huge amounts on such a platform but that is OK
+ * since sudo doesn't need to do so anyway.
  */
 #ifndef SIZE_MAX
 # ifdef SIZE_T_MAX
@@ -241,7 +241,7 @@ env_init(char * const envp[])
 
        env.env_len = len;
        env.env_size = len + 1 + 128;
-       env.envp = emalloc2(env.env_size, sizeof(char *));
+       env.envp = emallocarray(env.env_size, sizeof(char *));
 #ifdef ENV_DEBUG
        memset(env.envp, 0, env.env_size * sizeof(char *));
 #endif
@@ -755,7 +755,7 @@ rebuild_env(void)
     env.env_len = 0;
     env.env_size = 128;
     old_envp = env.envp;
-    env.envp = emalloc2(env.env_size, sizeof(char *));
+    env.envp = emallocarray(env.env_size, sizeof(char *));
 #ifdef ENV_DEBUG
     memset(env.envp, 0, env.env_size * sizeof(char *));
 #else
index 86790bc4b6ac8f25bca54b22d3cc7b2fe60df60b..f7b92112b253d1b7709cf166aedfadfde228dff9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2010-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -135,7 +135,7 @@ group_plugin_load(char *plugin_info)
             }
         }
        if (ac != 0)    {
-           argv = emalloc2(ac, sizeof(char *));
+           argv = emallocarray(ac, sizeof(char *));
            ac = 0;
            for ((cp = strtok(args, " \t")); cp; (cp = strtok(NULL, " \t")))
                argv[ac++] = cp;
index 1d12c6a34878260609b3be895070919b97eb148b..fcf6f60dc1ac0fb95e73a820c17824882b7eac1c 100644 (file)
@@ -2806,7 +2806,7 @@ sudo_ldap_result_add_entry(struct ldap_result *lres, LDAPMessage *entry)
      */
     if (++lres->nentries > lres->allocated_entries) {
        lres->allocated_entries += ALLOCATION_INCREMENT;
-       lres->entries = erealloc3(lres->entries, lres->allocated_entries,
+       lres->entries = ereallocarray(lres->entries, lres->allocated_entries,
            sizeof(lres->entries[0]));
     }
 
index bc1097ae1c37b57fcdc70f8b036db2e24c9dd55a..699dffe4eb5c0670db01f283793553dbc742686f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 1998-2005, 2007-2013
+ * Copyright (c) 1996, 1998-2005, 2007-2014
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -245,7 +245,7 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1,
     } else {
        if (sudo_user.max_groups > 0) {
            ngids = sudo_user.max_groups;
-           gids = emalloc2(ngids, sizeof(GETGROUPS_T));
+           gids = emallocarray(ngids, sizeof(GETGROUPS_T));
            (void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids);
        } else {
 #if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX)
@@ -253,10 +253,10 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1,
            if (ngids < 0)
 #endif
                ngids = NGROUPS_MAX * 2;
-           gids = emalloc2(ngids, sizeof(GETGROUPS_T));
+           gids = emallocarray(ngids, sizeof(GETGROUPS_T));
            if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) {
                efree(gids);
-               gids = emalloc2(ngids, sizeof(GETGROUPS_T));
+               gids = emallocarray(ngids, sizeof(GETGROUPS_T));
                if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1)
                    ngids = -1;
            }
index 6e960a84176d91fcfd47690c44ffe72255af3a0a..f5f9e00291906bed2c01fab6671b62dc29406d5e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2003-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  * Copyright (c) 2011 Daniel Kopecek <dkopecek@redhat.com>
  *
  * This code is derived from software contributed by Aaron Spangler.
@@ -132,7 +132,7 @@ sudo_sss_attrcpy(struct sss_sudo_attr *dst, const struct sss_sudo_attr *src)
 
      dst->name = estrdup(src->name);
      dst->num_values = src->num_values;
-     dst->values = emalloc2(dst->num_values, sizeof(char *));
+     dst->values = emallocarray(dst->num_values, sizeof(char *));
 
      for (i = 0; i < dst->num_values; ++i)
          dst->values[i] = estrdup(src->values[i]);
@@ -150,7 +150,7 @@ sudo_sss_rulecpy(struct sss_sudo_rule *dst, const struct sss_sudo_rule *src)
      sudo_debug_printf(SUDO_DEBUG_INFO, "emalloc: cnt=%d", src->num_attrs);
 
      dst->num_attrs = src->num_attrs;
-     dst->attrs = emalloc2(dst->num_attrs, sizeof(struct sss_sudo_attr));
+     dst->attrs = emallocarray(dst->num_attrs, sizeof(struct sss_sudo_attr));
 
      for (i = 0; i < dst->num_attrs; ++i)
          sudo_sss_attrcpy(dst->attrs + i, src->attrs + i);
@@ -185,7 +185,7 @@ sudo_sss_filter_result(struct sudo_sss_handle *handle,
 
     out_res = emalloc(sizeof(struct sss_sudo_result));
     out_res->rules = in_res->num_rules > 0 ?
-       emalloc2(in_res->num_rules, sizeof(struct sss_sudo_rule)) : NULL;
+       emallocarray(in_res->num_rules, sizeof(struct sss_sudo_rule)) : NULL;
     out_res->num_rules = 0;
 
     for (i = l = 0; i < in_res->num_rules; ++i) {
@@ -209,7 +209,7 @@ sudo_sss_filter_result(struct sudo_sss_handle *handle,
            in_res->num_rules, l);
        if (l > 0) {
            out_res->rules =
-               erealloc3(out_res->rules, l, sizeof(struct sss_sudo_rule));
+               ereallocarray(out_res->rules, l, sizeof(struct sss_sudo_rule));
        } else {
            efree(out_res->rules);
            out_res->rules = NULL;
index 7fbd01139b5dfe835ff8bd7464989cf20438241d..c5945288bfa337959226b971ee74ef4da515a144 100644 (file)
@@ -250,13 +250,13 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
      */
     if (argc == 0) {
        NewArgc = 1;
-       NewArgv = emalloc2(NewArgc + 1, sizeof(char *));
+       NewArgv = emallocarray(NewArgc + 1, sizeof(char *));
        NewArgv[0] = user_cmnd;
        NewArgv[1] = NULL;
     } else {
        /* Must leave an extra slot before NewArgv for bash's --login */
        NewArgc = argc;
-       NewArgv = emalloc2(NewArgc + 2, sizeof(char *));
+       NewArgv = emallocarray(NewArgc + 2, sizeof(char *));
        memcpy(++NewArgv, argv, argc * sizeof(char *));
        NewArgv[NewArgc] = NULL;
        if (ISSET(sudo_mode, MODE_LOGIN_SHELL) && runas_pw != NULL)
@@ -1020,7 +1020,7 @@ resolve_editor(const char *ed, size_t edlen, int nfiles, char **files, char ***a
        efree(editor);
        debug_return_str(NULL);
     }
-    nargv = (char **) emalloc2(nargc + 1 + nfiles + 1, sizeof(char *));
+    nargv = (char **) emallocarray(nargc + 1 + nfiles + 1, sizeof(char *));
     for (ac = 0; cp != NULL && ac < nargc; ac++) {
        nargv[ac] = cp;
        cp = strtok(NULL, " \t");
index b3926d1855ee86b4c34b261a541612b191801738..de4cb767173f2959dae467afb2fdd4e5f1d23857 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2009-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -502,8 +502,8 @@ replay_session(const double max_wait, const char *decimal)
                    /* Store the line in iov followed by \r\n pair. */
                    if (iovcnt + 3 > iovmax) {
                        iov = iovmax ?
-                           erealloc3(iov, iovmax <<= 1, sizeof(*iov)) :
-                           emalloc2(iovmax = 32, sizeof(*iov));
+                           ereallocarray(iov, iovmax <<= 1, sizeof(*iov)) :
+                           emallocarray(iovmax = 32, sizeof(*iov));
                    }
                    linelen = (size_t)(ep - cp) + 1;
                    iov[iovcnt].iov_base = cp;
@@ -1020,7 +1020,7 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
     pathbuf[sdlen] = '\0';
 
     /* Store potential session dirs for sorting. */
-    sessions = emalloc2(sessions_size, sizeof(char *));
+    sessions = emallocarray(sessions_size, sizeof(char *));
     while ((dp = readdir(d)) != NULL) {
        /* Skip "." and ".." */
        if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' ||
@@ -1040,7 +1040,7 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
        /* Add name to session list. */
        if (sessions_len + 1 > sessions_size) {
            sessions_size <<= 1;
-           sessions = erealloc3(sessions, sessions_size, sizeof(char *));
+           sessions = ereallocarray(sessions, sessions_size, sizeof(char *));
        }
        sessions[sessions_len++] = estrdup(dp->d_name);
     }
index 79d8df360128918e6d0c918f1b7dd60c34e1747a..c491629f2097fbb7b720f68c350008f5f3c62de5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 1998-2005, 2007-2013
+ * Copyright (c) 1996, 1998-2005, 2007-2014
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -396,7 +396,7 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno)
     }
 
     /* Build up argument vector for the command */
-    av = emalloc2(ac, sizeof(char *));
+    av = emallocarray(ac, sizeof(char *));
     if ((av[0] = strrchr(editor, '/')) != NULL)
        av[0]++;
     else
index 06010782e51186d82344acb68efce1a6f2eadbe6..37257bc172dedfa6b1e8955daf8880eea1ad474e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2010, 2012, 2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -125,7 +125,7 @@ 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 = erealloc3(priv_environ, env_len + 2, sizeof(char *));
+       char **envp = ereallocarray(priv_environ, env_len + 2, sizeof(char *));
        if (environ != priv_environ)
            memcpy(envp, environ, env_len * sizeof(char *));
        envp[env_len++] = (char *)string;
index 1a54dd9c3bec03150dbf47fef52713dbad040545..9c94632a95058896976d39d530e06b446503583c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2009-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -100,7 +100,7 @@ disable_execute(char *const envp[])
     if (!enabled)
        env_size++;
 #endif
-    nenvp = emalloc2(env_size, sizeof(*envp));
+    nenvp = emallocarray(env_size, sizeof(*envp));
     memcpy(nenvp, envp, env_len * sizeof(*envp));
     nenvp[env_len] = NULL;
 
@@ -151,7 +151,7 @@ sudo_execve(const char *path, char *const argv[], char *const envp[], bool noexe
 
        for (argc = 0; argv[argc] != NULL; argc++)
            continue;
-       nargv = emalloc2(argc + 2, sizeof(char *));
+       nargv = emallocarray(argc + 2, sizeof(char *));
        nargv[0] = "sh";
        nargv[1] = (char *)path;
        memcpy(nargv + 2, argv + 1, argc * sizeof(char *));
index d4b6305b4debd81aa731b28cf0df62f02008ad8b..6363da8f868794e2101eef31a0f9c16295d85565 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1993-1996, 1998-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1993-1996, 1998-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -183,7 +183,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
     int env_size = 32;
     debug_decl(parse_args, SUDO_DEBUG_ARGS)
 
-    env_add = emalloc2(env_size, sizeof(char *));
+    env_add = emallocarray(env_size, sizeof(char *));
 
     /* Pass progname to plugin so it can call initprogname() */
     sudo_settings[ARG_PROGNAME].value = getprogname();
@@ -371,7 +371,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
        } else if (!got_end_of_args && is_envar) {
            if (nenv == env_size - 2) {
                env_size *= 2;
-               env_add = erealloc3(env_add, env_size, sizeof(char *));
+               env_add = ereallocarray(env_add, env_size, sizeof(char *));
            }
            env_add[nenv++] = argv[optind];
 
@@ -460,7 +460,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
            size_t cmnd_size = (size_t) (argv[argc - 1] - argv[0]) +
                strlen(argv[argc - 1]) + 1;
 
-           cmnd = dst = emalloc2(cmnd_size, 2);
+           cmnd = dst = emallocarray(cmnd_size, 2);
            for (av = argv; *av != NULL; av++) {
                for (src = *av; *src != '\0'; src++) {
                    /* quote potential meta characters */
@@ -477,7 +477,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
            ac += 2; /* -c cmnd */
        }
 
-       av = emalloc2(ac + 1, sizeof(char *));
+       av = emallocarray(ac + 1, sizeof(char *));
        av[0] = (char *)user_details.shell; /* plugin may override shell */
        if (cmnd != NULL) {
            av[1] = "-c";
@@ -495,7 +495,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
 #ifdef _PATH_SUDO_PLUGIN_DIR
     sudo_settings[ARG_PLUGIN_DIR].value = sudo_conf_plugin_dir_path();
 #endif
-    settings = emalloc2(NUM_SETTINGS + 1, sizeof(char *));
+    settings = emallocarray(NUM_SETTINGS + 1, sizeof(char *));
     for (i = 0, j = 0; i < NUM_SETTINGS; i++) {
        if (sudo_settings[i].value) {
            sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
index f81884a8306ce74a8519520f0736158c143e3b4c..abb07d8d21e42d09d45cb9d0e0d8b8b442b7f460 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2009-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  * Copyright (c) 2008 Dan Walsh <dwalsh@redhat.com>
  *
  * Borrowed heavily from newrole source code
@@ -398,7 +398,7 @@ selinux_execve(const char *path, char *const argv[], char *const envp[],
      */
     for (argc = 0; argv[argc] != NULL; argc++)
        continue;
-    nargv = emalloc2(argc + 2, sizeof(char *));
+    nargv = emallocarray(argc + 2, sizeof(char *));
     if (noexec)
        nargv[0] = *argv[0] == '-' ? "-sesh-noexec" : "sesh-noexec";
     else
index 971cf27197b6d4e5d49f9eba9883034eb91629ea..9b502d1eec3a7130442460d68d60230001ab0368 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2009-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -354,7 +354,7 @@ fill_group_list(struct user_details *ud, int system_maxgroups)
      */
     ud->ngroups = sudo_conf_max_groups();
     if (ud->ngroups > 0) {
-       ud->groups = emalloc2(ud->ngroups, sizeof(GETGROUPS_T));
+       ud->groups = emallocarray(ud->ngroups, sizeof(GETGROUPS_T));
        /* No error on insufficient space if user specified max_groups. */
        (void)getgrouplist(ud->username, ud->gid, ud->groups, &ud->ngroups);
        rval = 0;
@@ -369,7 +369,7 @@ fill_group_list(struct user_details *ud, int system_maxgroups)
        for (tries = 0; tries < 10 && rval == -1; tries++) {
            ud->ngroups <<= 1;
            efree(ud->groups);
-           ud->groups = emalloc2(ud->ngroups, sizeof(GETGROUPS_T));
+           ud->groups = emallocarray(ud->ngroups, sizeof(GETGROUPS_T));
            rval = getgrouplist(ud->username, ud->gid, ud->groups, &ud->ngroups);
        }
     }
@@ -396,7 +396,7 @@ 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 = emalloc2(ud->ngroups, sizeof(GETGROUPS_T));
+               ud->groups = emallocarray(ud->ngroups, sizeof(GETGROUPS_T));
                if (getgroups(ud->ngroups, ud->groups) < 0) {
                    efree(ud->groups);
                    ud->groups = NULL;
@@ -442,7 +442,7 @@ get_user_info(struct user_details *ud)
     debug_decl(get_user_info, SUDO_DEBUG_UTIL)
 
     /* XXX - bound check number of entries */
-    user_info = emalloc2(32, sizeof(char *));
+    user_info = emallocarray(32, sizeof(char *));
 
     ud->pid = getpid();
     ud->ppid = getppid();
index 6d2542dc4fc629f89976be88b61036a4aac12b75..6073c79ffa00ca59fa7c982940c30188edb7b9c5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2008, 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2004-2008, 2010-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -147,7 +147,7 @@ sudo_edit(struct command_details *command_details)
      * For each file specified by the user, make a temporary version
      * and copy the contents of the original to it.
      */
-    tf = emalloc2(nfiles, sizeof(*tf));
+    tf = emallocarray(nfiles, sizeof(*tf));
     memset(tf, 0, nfiles * sizeof(*tf));
     for (i = 0, j = 0; i < nfiles; i++) {
        rc = -1;
@@ -230,7 +230,7 @@ sudo_edit(struct command_details *command_details)
      * to create a new argv.
      */
     nargc = editor_argc + nfiles;
-    nargv = (char **) emalloc2(nargc + 1, sizeof(char *));
+    nargv = (char **) emallocarray(nargc + 1, sizeof(char *));
     for (ac = 0; ac < editor_argc; ac++)
        nargv[ac] = command_details->argv[ac];
     for (i = 0; i < nfiles && ac < nargc; )
index 1996a250a26d5d296cb5068ddeba2447fe1122f0..2edf2443ab3f2da89d78ce0c2d641807f2f30a24 100644 (file)
@@ -263,7 +263,7 @@ sudo_ttyname_scan(const char *dir, dev_t rdev, bool builtin)
                /* Add to list of subdirs to search. */
                if (num_subdirs + 1 > max_subdirs) {
                    max_subdirs += 64;
-                   subdirs = erealloc3(subdirs, max_subdirs, sizeof(char *));
+                   subdirs = ereallocarray(subdirs, max_subdirs, sizeof(char *));
                }
                subdirs[num_subdirs++] = estrdup(pathbuf);
            }