From: Todd C. Miller Date: Tue, 22 Apr 2014 22:02:28 +0000 (-0600) Subject: Rename emalloc2() -> emallocarray() and erealloc3() -> ereallocarray(). X-Git-Tag: SUDO_1_8_11^2~218 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=134b2a4228c02bc9146041f0b226a1d9af6da643;p=sudo Rename emalloc2() -> emallocarray() and erealloc3() -> ereallocarray(). --- diff --git a/common/alloc.c b/common/alloc.c index f9775a9cb..46a31135e 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2005, 2007, 2010-2013 + * Copyright (c) 1999-2005, 2007, 2010-2014 * Todd C. Miller * * 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); diff --git a/common/event_poll.c b/common/event_poll.c index 5cf35cca7..dfe1153f8 100644 --- a/common/event_poll.c +++ b/common/event_poll.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Todd C. Miller + * Copyright (c) 2013-2014 Todd C. Miller * * 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; } diff --git a/common/gidlist.c b/common/gidlist.c index 9d5d4805f..aaba61275 100644 --- a/common/gidlist.c +++ b/common/gidlist.c @@ -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; diff --git a/common/sudo_conf.c b/common/sudo_conf.c index 3d8d6bb57..d16bc1212 100644 --- a/common/sudo_conf.c +++ b/common/sudo_conf.c @@ -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)); diff --git a/include/alloc.h b/include/alloc.h index 23fa6de7c..f7c566c7c 100644 --- a/include/alloc.h +++ b/include/alloc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2010, 2012-1013 + * Copyright (c) 2009-2010, 2012-1014 * Todd C. Miller * * 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; diff --git a/plugins/sudoers/auth/sia.c b/plugins/sudoers/auth/sia.c index c6050ca0b..7de883f41 100644 --- a/plugins/sudoers/auth/sia.c +++ b/plugins/sudoers/auth/sia.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2005, 2007, 2010-2013 + * Copyright (c) 1999-2005, 2007, 2010-2014 * Todd C. Miller * * 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]; diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index 466469d5a..1265c293b 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2005, 2007-2013 + * Copyright (c) 2000-2005, 2007-2014 * Todd C. Miller * * 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 diff --git a/plugins/sudoers/group_plugin.c b/plugins/sudoers/group_plugin.c index 86790bc4b..f7b92112b 100644 --- a/plugins/sudoers/group_plugin.c +++ b/plugins/sudoers/group_plugin.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Todd C. Miller + * Copyright (c) 2010-2014 Todd C. Miller * * 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; diff --git a/plugins/sudoers/ldap.c b/plugins/sudoers/ldap.c index 1d12c6a34..fcf6f60dc 100644 --- a/plugins/sudoers/ldap.c +++ b/plugins/sudoers/ldap.c @@ -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])); } diff --git a/plugins/sudoers/pwutil_impl.c b/plugins/sudoers/pwutil_impl.c index bc1097ae1..699dffe4e 100644 --- a/plugins/sudoers/pwutil_impl.c +++ b/plugins/sudoers/pwutil_impl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1998-2005, 2007-2013 + * Copyright (c) 1996, 1998-2005, 2007-2014 * Todd C. Miller * * 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; } diff --git a/plugins/sudoers/sssd.c b/plugins/sudoers/sssd.c index 6e960a841..f5f9e0029 100644 --- a/plugins/sudoers/sssd.c +++ b/plugins/sudoers/sssd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2013 Todd C. Miller + * Copyright (c) 2003-2014 Todd C. Miller * Copyright (c) 2011 Daniel Kopecek * * 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; diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 7fbd01139..c5945288b 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -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"); diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index b3926d185..de4cb7671 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2013 Todd C. Miller + * Copyright (c) 2009-2014 Todd C. Miller * * 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); } diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 79d8df360..c491629f2 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1998-2005, 2007-2013 + * Copyright (c) 1996, 1998-2005, 2007-2014 * Todd C. Miller * * 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 diff --git a/src/env_hooks.c b/src/env_hooks.c index 06010782e..37257bc17 100644 --- a/src/env_hooks.c +++ b/src/env_hooks.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012 Todd C. Miller + * Copyright (c) 2010, 2012, 2014 Todd C. Miller * * 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; diff --git a/src/exec_common.c b/src/exec_common.c index 1a54dd9c3..9c94632a9 100644 --- a/src/exec_common.c +++ b/src/exec_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2013 Todd C. Miller + * Copyright (c) 2009-2014 Todd C. Miller * * 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 *)); diff --git a/src/parse_args.c b/src/parse_args.c index d4b6305b4..6363da8f8 100644 --- a/src/parse_args.c +++ b/src/parse_args.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993-1996, 1998-2013 Todd C. Miller + * Copyright (c) 1993-1996, 1998-2014 Todd C. Miller * * 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", diff --git a/src/selinux.c b/src/selinux.c index f81884a83..abb07d8d2 100644 --- a/src/selinux.c +++ b/src/selinux.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2013 Todd C. Miller + * Copyright (c) 2009-2014 Todd C. Miller * Copyright (c) 2008 Dan Walsh * * 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 diff --git a/src/sudo.c b/src/sudo.c index 971cf2719..9b502d1ee 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2013 Todd C. Miller + * Copyright (c) 2009-2014 Todd C. Miller * * 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(); diff --git a/src/sudo_edit.c b/src/sudo_edit.c index 6d2542dc4..6073c79ff 100644 --- a/src/sudo_edit.c +++ b/src/sudo_edit.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2008, 2010-2013 Todd C. Miller + * Copyright (c) 2004-2008, 2010-2014 Todd C. Miller * * 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; ) diff --git a/src/ttyname.c b/src/ttyname.c index 1996a250a..2edf2443a 100644 --- a/src/ttyname.c +++ b/src/ttyname.c @@ -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); }