Rename emalloc2() -> emallocarray() and erealloc3() -> ereallocarray().
This commit is contained in:
@@ -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>
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* 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
|
* 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
|
* 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.
|
* platform but that is OK since sudo doesn't need to do so anyway.
|
||||||
*/
|
*/
|
||||||
#ifndef SIZE_MAX
|
#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.
|
* if overflow would occur or if the system malloc(3) fails.
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
emalloc2(size_t nmemb, size_t size)
|
emallocarray(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
if (nmemb == 0 || size == 0)
|
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)
|
if (nmemb > SIZE_MAX / size)
|
||||||
fatalx_nodebug(_("internal error, %s overflow"), "emalloc2");
|
fatalx_nodebug(_("internal error, %s overflow"), "emallocarray");
|
||||||
|
|
||||||
size *= nmemb;
|
size *= nmemb;
|
||||||
if ((ptr = malloc(size)) == NULL)
|
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.
|
* 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)
|
* You can call erealloc() with a NULL pointer even if the system realloc(3)
|
||||||
* does not support this.
|
* does not support this.
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
erealloc3(void *ptr, size_t nmemb, size_t size)
|
ereallocarray(void *ptr, size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (nmemb == 0 || size == 0)
|
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)
|
if (nmemb > SIZE_MAX / size)
|
||||||
fatalx_nodebug(_("internal error, %s overflow"), "erealloc3");
|
fatalx_nodebug(_("internal error, %s overflow"), "ereallocarray");
|
||||||
|
|
||||||
size *= nmemb;
|
size *= nmemb;
|
||||||
ptr = ptr ? realloc(ptr, size) : malloc(size);
|
ptr = ptr ? realloc(ptr, size) : malloc(size);
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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_high = -1;
|
||||||
base->pfd_max = 32;
|
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++) {
|
for (i = 0; i < base->pfd_max; i++) {
|
||||||
base->pfds[i].fd = -1;
|
base->pfds[i].fd = -1;
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev)
|
|||||||
int i;
|
int i;
|
||||||
base->pfd_max <<= 1;
|
base->pfd_max <<= 1;
|
||||||
base->pfds =
|
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++) {
|
for (i = base->pfd_free; i < base->pfd_max; i++) {
|
||||||
base->pfds[i].fd = -1;
|
base->pfds[i].fd = -1;
|
||||||
}
|
}
|
||||||
|
@@ -67,7 +67,7 @@ parse_gid_list(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp)
|
|||||||
ngids++;
|
ngids++;
|
||||||
/* Allocate and fill in array. */
|
/* Allocate and fill in array. */
|
||||||
if (ngids != 0) {
|
if (ngids != 0) {
|
||||||
gids = emalloc2(ngids, sizeof(GETGROUPS_T));
|
gids = emallocarray(ngids, sizeof(GETGROUPS_T));
|
||||||
ngids = 0;
|
ngids = 0;
|
||||||
if (basegid != NULL)
|
if (basegid != NULL)
|
||||||
gids[ngids++] = *basegid;
|
gids[ngids++] = *basegid;
|
||||||
|
@@ -294,7 +294,7 @@ set_plugin(const char *entry, const char *conf_file)
|
|||||||
while (isblank((unsigned char)*ep))
|
while (isblank((unsigned char)*ep))
|
||||||
ep++;
|
ep++;
|
||||||
}
|
}
|
||||||
options = emalloc2(nopts + 1, sizeof(*options));
|
options = emallocarray(nopts + 1, sizeof(*options));
|
||||||
/* Fill in options array, there is at least one element. */
|
/* Fill in options array, there is at least one element. */
|
||||||
for (nopts = 0; (ep = strpbrk(cp, " \t")) != NULL; ) {
|
for (nopts = 0; (ep = strpbrk(cp, " \t")) != NULL; ) {
|
||||||
options[nopts++] = estrndup(cp, (size_t)(ep - cp));
|
options[nopts++] = estrndup(cp, (size_t)(ep - cp));
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2010, 2012-1013
|
* Copyright (c) 2009-2010, 2012-1014
|
||||||
* Todd C. Miller <Todd.Miller@courtesan.com>
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* 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);
|
int evasprintf(char **, const char *, va_list) __printflike(2, 0);
|
||||||
void *ecalloc(size_t, size_t) __malloc_like;
|
void *ecalloc(size_t, size_t) __malloc_like;
|
||||||
void *emalloc(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 *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);
|
void *erecalloc(void *, size_t, size_t, size_t);
|
||||||
char *estrdup(const char *) __malloc_like;
|
char *estrdup(const char *) __malloc_like;
|
||||||
char *estrndup(const char *, size_t) __malloc_like;
|
char *estrndup(const char *, size_t) __malloc_like;
|
||||||
|
@@ -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>
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* 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() */
|
/* Rebuild argv for sia_ses_init() */
|
||||||
sudo_argc = NewArgc + 1;
|
sudo_argc = NewArgc + 1;
|
||||||
sudo_argv = emalloc2(sudo_argc + 1, sizeof(char *));
|
sudo_argv = emallocarray(sudo_argc + 1, sizeof(char *));
|
||||||
sudo_argv[0] = "sudo";
|
sudo_argv[0] = "sudo";
|
||||||
for (i = 0; i < NewArgc; i++)
|
for (i = 0; i < NewArgc; i++)
|
||||||
sudo_argv[i + 1] = NewArgv[i];
|
sudo_argv[i + 1] = NewArgv[i];
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000-2005, 2007-2013
|
* Copyright (c) 2000-2005, 2007-2014
|
||||||
* Todd C. Miller <Todd.Miller@courtesan.com>
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* 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
|
* 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
|
* could be signed (as it is on SunOS 4.x). This just means that
|
||||||
* emalloc2() and erealloc3() cannot allocate huge amounts on such a
|
* we cannot allocate huge amounts on such a platform but that is OK
|
||||||
* platform but that is OK since sudo doesn't need to do so anyway.
|
* since sudo doesn't need to do so anyway.
|
||||||
*/
|
*/
|
||||||
#ifndef SIZE_MAX
|
#ifndef SIZE_MAX
|
||||||
# ifdef SIZE_T_MAX
|
# ifdef SIZE_T_MAX
|
||||||
@@ -241,7 +241,7 @@ env_init(char * const envp[])
|
|||||||
|
|
||||||
env.env_len = len;
|
env.env_len = len;
|
||||||
env.env_size = len + 1 + 128;
|
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
|
#ifdef ENV_DEBUG
|
||||||
memset(env.envp, 0, env.env_size * sizeof(char *));
|
memset(env.envp, 0, env.env_size * sizeof(char *));
|
||||||
#endif
|
#endif
|
||||||
@@ -755,7 +755,7 @@ rebuild_env(void)
|
|||||||
env.env_len = 0;
|
env.env_len = 0;
|
||||||
env.env_size = 128;
|
env.env_size = 128;
|
||||||
old_envp = env.envp;
|
old_envp = env.envp;
|
||||||
env.envp = emalloc2(env.env_size, sizeof(char *));
|
env.envp = emallocarray(env.env_size, sizeof(char *));
|
||||||
#ifdef ENV_DEBUG
|
#ifdef ENV_DEBUG
|
||||||
memset(env.envp, 0, env.env_size * sizeof(char *));
|
memset(env.envp, 0, env.env_size * sizeof(char *));
|
||||||
#else
|
#else
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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) {
|
if (ac != 0) {
|
||||||
argv = emalloc2(ac, sizeof(char *));
|
argv = emallocarray(ac, sizeof(char *));
|
||||||
ac = 0;
|
ac = 0;
|
||||||
for ((cp = strtok(args, " \t")); cp; (cp = strtok(NULL, " \t")))
|
for ((cp = strtok(args, " \t")); cp; (cp = strtok(NULL, " \t")))
|
||||||
argv[ac++] = cp;
|
argv[ac++] = cp;
|
||||||
|
@@ -2806,7 +2806,7 @@ sudo_ldap_result_add_entry(struct ldap_result *lres, LDAPMessage *entry)
|
|||||||
*/
|
*/
|
||||||
if (++lres->nentries > lres->allocated_entries) {
|
if (++lres->nentries > lres->allocated_entries) {
|
||||||
lres->allocated_entries += ALLOCATION_INCREMENT;
|
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]));
|
sizeof(lres->entries[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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>
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* 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 {
|
} else {
|
||||||
if (sudo_user.max_groups > 0) {
|
if (sudo_user.max_groups > 0) {
|
||||||
ngids = sudo_user.max_groups;
|
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);
|
(void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids);
|
||||||
} else {
|
} else {
|
||||||
#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX)
|
#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)
|
if (ngids < 0)
|
||||||
#endif
|
#endif
|
||||||
ngids = NGROUPS_MAX * 2;
|
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) {
|
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) {
|
||||||
efree(gids);
|
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)
|
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1)
|
||||||
ngids = -1;
|
ngids = -1;
|
||||||
}
|
}
|
||||||
|
@@ -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>
|
* Copyright (c) 2011 Daniel Kopecek <dkopecek@redhat.com>
|
||||||
*
|
*
|
||||||
* This code is derived from software contributed by Aaron Spangler.
|
* 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->name = estrdup(src->name);
|
||||||
dst->num_values = src->num_values;
|
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)
|
for (i = 0; i < dst->num_values; ++i)
|
||||||
dst->values[i] = estrdup(src->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);
|
sudo_debug_printf(SUDO_DEBUG_INFO, "emalloc: cnt=%d", src->num_attrs);
|
||||||
|
|
||||||
dst->num_attrs = 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)
|
for (i = 0; i < dst->num_attrs; ++i)
|
||||||
sudo_sss_attrcpy(dst->attrs + i, src->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 = emalloc(sizeof(struct sss_sudo_result));
|
||||||
out_res->rules = in_res->num_rules > 0 ?
|
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;
|
out_res->num_rules = 0;
|
||||||
|
|
||||||
for (i = l = 0; i < in_res->num_rules; ++i) {
|
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);
|
in_res->num_rules, l);
|
||||||
if (l > 0) {
|
if (l > 0) {
|
||||||
out_res->rules =
|
out_res->rules =
|
||||||
erealloc3(out_res->rules, l, sizeof(struct sss_sudo_rule));
|
ereallocarray(out_res->rules, l, sizeof(struct sss_sudo_rule));
|
||||||
} else {
|
} else {
|
||||||
efree(out_res->rules);
|
efree(out_res->rules);
|
||||||
out_res->rules = NULL;
|
out_res->rules = NULL;
|
||||||
|
@@ -250,13 +250,13 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
|
|||||||
*/
|
*/
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
NewArgc = 1;
|
NewArgc = 1;
|
||||||
NewArgv = emalloc2(NewArgc + 1, sizeof(char *));
|
NewArgv = emallocarray(NewArgc + 1, sizeof(char *));
|
||||||
NewArgv[0] = user_cmnd;
|
NewArgv[0] = user_cmnd;
|
||||||
NewArgv[1] = NULL;
|
NewArgv[1] = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* Must leave an extra slot before NewArgv for bash's --login */
|
/* Must leave an extra slot before NewArgv for bash's --login */
|
||||||
NewArgc = argc;
|
NewArgc = argc;
|
||||||
NewArgv = emalloc2(NewArgc + 2, sizeof(char *));
|
NewArgv = emallocarray(NewArgc + 2, sizeof(char *));
|
||||||
memcpy(++NewArgv, argv, argc * sizeof(char *));
|
memcpy(++NewArgv, argv, argc * sizeof(char *));
|
||||||
NewArgv[NewArgc] = NULL;
|
NewArgv[NewArgc] = NULL;
|
||||||
if (ISSET(sudo_mode, MODE_LOGIN_SHELL) && runas_pw != 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);
|
efree(editor);
|
||||||
debug_return_str(NULL);
|
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++) {
|
for (ac = 0; cp != NULL && ac < nargc; ac++) {
|
||||||
nargv[ac] = cp;
|
nargv[ac] = cp;
|
||||||
cp = strtok(NULL, " \t");
|
cp = strtok(NULL, " \t");
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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. */
|
/* Store the line in iov followed by \r\n pair. */
|
||||||
if (iovcnt + 3 > iovmax) {
|
if (iovcnt + 3 > iovmax) {
|
||||||
iov = iovmax ?
|
iov = iovmax ?
|
||||||
erealloc3(iov, iovmax <<= 1, sizeof(*iov)) :
|
ereallocarray(iov, iovmax <<= 1, sizeof(*iov)) :
|
||||||
emalloc2(iovmax = 32, sizeof(*iov));
|
emallocarray(iovmax = 32, sizeof(*iov));
|
||||||
}
|
}
|
||||||
linelen = (size_t)(ep - cp) + 1;
|
linelen = (size_t)(ep - cp) + 1;
|
||||||
iov[iovcnt].iov_base = cp;
|
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';
|
pathbuf[sdlen] = '\0';
|
||||||
|
|
||||||
/* Store potential session dirs for sorting. */
|
/* Store potential session dirs for sorting. */
|
||||||
sessions = emalloc2(sessions_size, sizeof(char *));
|
sessions = emallocarray(sessions_size, sizeof(char *));
|
||||||
while ((dp = readdir(d)) != NULL) {
|
while ((dp = readdir(d)) != NULL) {
|
||||||
/* Skip "." and ".." */
|
/* Skip "." and ".." */
|
||||||
if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' ||
|
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. */
|
/* Add name to session list. */
|
||||||
if (sessions_len + 1 > sessions_size) {
|
if (sessions_len + 1 > sessions_size) {
|
||||||
sessions_size <<= 1;
|
sessions_size <<= 1;
|
||||||
sessions = erealloc3(sessions, sessions_size, sizeof(char *));
|
sessions = ereallocarray(sessions, sessions_size, sizeof(char *));
|
||||||
}
|
}
|
||||||
sessions[sessions_len++] = estrdup(dp->d_name);
|
sessions[sessions_len++] = estrdup(dp->d_name);
|
||||||
}
|
}
|
||||||
|
@@ -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>
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* 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 */
|
/* Build up argument vector for the command */
|
||||||
av = emalloc2(ac, sizeof(char *));
|
av = emallocarray(ac, sizeof(char *));
|
||||||
if ((av[0] = strrchr(editor, '/')) != NULL)
|
if ((av[0] = strrchr(editor, '/')) != NULL)
|
||||||
av[0]++;
|
av[0]++;
|
||||||
else
|
else
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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. */
|
/* Append at the end if not already found. */
|
||||||
if (!found) {
|
if (!found) {
|
||||||
size_t env_len = (size_t)(ep - environ);
|
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)
|
if (environ != priv_environ)
|
||||||
memcpy(envp, environ, env_len * sizeof(char *));
|
memcpy(envp, environ, env_len * sizeof(char *));
|
||||||
envp[env_len++] = (char *)string;
|
envp[env_len++] = (char *)string;
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -100,7 +100,7 @@ disable_execute(char *const envp[])
|
|||||||
if (!enabled)
|
if (!enabled)
|
||||||
env_size++;
|
env_size++;
|
||||||
#endif
|
#endif
|
||||||
nenvp = emalloc2(env_size, sizeof(*envp));
|
nenvp = emallocarray(env_size, sizeof(*envp));
|
||||||
memcpy(nenvp, envp, env_len * sizeof(*envp));
|
memcpy(nenvp, envp, env_len * sizeof(*envp));
|
||||||
nenvp[env_len] = NULL;
|
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++)
|
for (argc = 0; argv[argc] != NULL; argc++)
|
||||||
continue;
|
continue;
|
||||||
nargv = emalloc2(argc + 2, sizeof(char *));
|
nargv = emallocarray(argc + 2, sizeof(char *));
|
||||||
nargv[0] = "sh";
|
nargv[0] = "sh";
|
||||||
nargv[1] = (char *)path;
|
nargv[1] = (char *)path;
|
||||||
memcpy(nargv + 2, argv + 1, argc * sizeof(char *));
|
memcpy(nargv + 2, argv + 1, argc * sizeof(char *));
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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;
|
int env_size = 32;
|
||||||
debug_decl(parse_args, SUDO_DEBUG_ARGS)
|
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() */
|
/* Pass progname to plugin so it can call initprogname() */
|
||||||
sudo_settings[ARG_PROGNAME].value = getprogname();
|
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) {
|
} else if (!got_end_of_args && is_envar) {
|
||||||
if (nenv == env_size - 2) {
|
if (nenv == env_size - 2) {
|
||||||
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];
|
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]) +
|
size_t cmnd_size = (size_t) (argv[argc - 1] - argv[0]) +
|
||||||
strlen(argv[argc - 1]) + 1;
|
strlen(argv[argc - 1]) + 1;
|
||||||
|
|
||||||
cmnd = dst = emalloc2(cmnd_size, 2);
|
cmnd = dst = emallocarray(cmnd_size, 2);
|
||||||
for (av = argv; *av != NULL; av++) {
|
for (av = argv; *av != NULL; av++) {
|
||||||
for (src = *av; *src != '\0'; src++) {
|
for (src = *av; *src != '\0'; src++) {
|
||||||
/* quote potential meta characters */
|
/* quote potential meta characters */
|
||||||
@@ -477,7 +477,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
|
|||||||
ac += 2; /* -c cmnd */
|
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 */
|
av[0] = (char *)user_details.shell; /* plugin may override shell */
|
||||||
if (cmnd != NULL) {
|
if (cmnd != NULL) {
|
||||||
av[1] = "-c";
|
av[1] = "-c";
|
||||||
@@ -495,7 +495,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
|
|||||||
#ifdef _PATH_SUDO_PLUGIN_DIR
|
#ifdef _PATH_SUDO_PLUGIN_DIR
|
||||||
sudo_settings[ARG_PLUGIN_DIR].value = sudo_conf_plugin_dir_path();
|
sudo_settings[ARG_PLUGIN_DIR].value = sudo_conf_plugin_dir_path();
|
||||||
#endif
|
#endif
|
||||||
settings = emalloc2(NUM_SETTINGS + 1, sizeof(char *));
|
settings = emallocarray(NUM_SETTINGS + 1, sizeof(char *));
|
||||||
for (i = 0, j = 0; i < NUM_SETTINGS; i++) {
|
for (i = 0, j = 0; i < NUM_SETTINGS; i++) {
|
||||||
if (sudo_settings[i].value) {
|
if (sudo_settings[i].value) {
|
||||||
sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
|
sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
|
||||||
|
@@ -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>
|
* Copyright (c) 2008 Dan Walsh <dwalsh@redhat.com>
|
||||||
*
|
*
|
||||||
* Borrowed heavily from newrole source code
|
* 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++)
|
for (argc = 0; argv[argc] != NULL; argc++)
|
||||||
continue;
|
continue;
|
||||||
nargv = emalloc2(argc + 2, sizeof(char *));
|
nargv = emallocarray(argc + 2, sizeof(char *));
|
||||||
if (noexec)
|
if (noexec)
|
||||||
nargv[0] = *argv[0] == '-' ? "-sesh-noexec" : "sesh-noexec";
|
nargv[0] = *argv[0] == '-' ? "-sesh-noexec" : "sesh-noexec";
|
||||||
else
|
else
|
||||||
|
10
src/sudo.c
10
src/sudo.c
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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();
|
ud->ngroups = sudo_conf_max_groups();
|
||||||
if (ud->ngroups > 0) {
|
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. */
|
/* No error on insufficient space if user specified max_groups. */
|
||||||
(void)getgrouplist(ud->username, ud->gid, ud->groups, &ud->ngroups);
|
(void)getgrouplist(ud->username, ud->gid, ud->groups, &ud->ngroups);
|
||||||
rval = 0;
|
rval = 0;
|
||||||
@@ -369,7 +369,7 @@ fill_group_list(struct user_details *ud, int system_maxgroups)
|
|||||||
for (tries = 0; tries < 10 && rval == -1; tries++) {
|
for (tries = 0; tries < 10 && rval == -1; tries++) {
|
||||||
ud->ngroups <<= 1;
|
ud->ngroups <<= 1;
|
||||||
efree(ud->groups);
|
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);
|
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) {
|
if ((ud->ngroups = getgroups(0, NULL)) > 0) {
|
||||||
/* Use groups from kernel if not too many or source is static. */
|
/* Use groups from kernel if not too many or source is static. */
|
||||||
if (ud->ngroups < maxgroups || group_source == GROUP_SOURCE_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) {
|
if (getgroups(ud->ngroups, ud->groups) < 0) {
|
||||||
efree(ud->groups);
|
efree(ud->groups);
|
||||||
ud->groups = NULL;
|
ud->groups = NULL;
|
||||||
@@ -442,7 +442,7 @@ get_user_info(struct user_details *ud)
|
|||||||
debug_decl(get_user_info, SUDO_DEBUG_UTIL)
|
debug_decl(get_user_info, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
/* XXX - bound check number of entries */
|
/* XXX - bound check number of entries */
|
||||||
user_info = emalloc2(32, sizeof(char *));
|
user_info = emallocarray(32, sizeof(char *));
|
||||||
|
|
||||||
ud->pid = getpid();
|
ud->pid = getpid();
|
||||||
ud->ppid = getppid();
|
ud->ppid = getppid();
|
||||||
|
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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
|
* For each file specified by the user, make a temporary version
|
||||||
* and copy the contents of the original to it.
|
* 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));
|
memset(tf, 0, nfiles * sizeof(*tf));
|
||||||
for (i = 0, j = 0; i < nfiles; i++) {
|
for (i = 0, j = 0; i < nfiles; i++) {
|
||||||
rc = -1;
|
rc = -1;
|
||||||
@@ -230,7 +230,7 @@ sudo_edit(struct command_details *command_details)
|
|||||||
* to create a new argv.
|
* to create a new argv.
|
||||||
*/
|
*/
|
||||||
nargc = editor_argc + nfiles;
|
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++)
|
for (ac = 0; ac < editor_argc; ac++)
|
||||||
nargv[ac] = command_details->argv[ac];
|
nargv[ac] = command_details->argv[ac];
|
||||||
for (i = 0; i < nfiles && ac < nargc; )
|
for (i = 0; i < nfiles && ac < nargc; )
|
||||||
|
@@ -263,7 +263,7 @@ sudo_ttyname_scan(const char *dir, dev_t rdev, bool builtin)
|
|||||||
/* Add to list of subdirs to search. */
|
/* Add to list of subdirs to search. */
|
||||||
if (num_subdirs + 1 > max_subdirs) {
|
if (num_subdirs + 1 > max_subdirs) {
|
||||||
max_subdirs += 64;
|
max_subdirs += 64;
|
||||||
subdirs = erealloc3(subdirs, max_subdirs, sizeof(char *));
|
subdirs = ereallocarray(subdirs, max_subdirs, sizeof(char *));
|
||||||
}
|
}
|
||||||
subdirs[num_subdirs++] = estrdup(pathbuf);
|
subdirs[num_subdirs++] = estrdup(pathbuf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user