Add some debugging printfs when malloc fails and we don't have an

explicit call to sudo_warnx().
This commit is contained in:
Todd C. Miller
2015-07-14 15:28:01 -06:00
parent 108bfb7af3
commit d4211081c0
11 changed files with 179 additions and 84 deletions

View File

@@ -66,6 +66,8 @@ sudo_lbuf_destroy_v1(struct sudo_lbuf *lbuf)
static bool static bool
sudo_lbuf_expand(struct sudo_lbuf *lbuf, int extra) sudo_lbuf_expand(struct sudo_lbuf *lbuf, int extra)
{ {
debug_decl(sudo_lbuf_expand, SUDO_DEBUG_UTIL)
if (lbuf->len + extra + 1 >= lbuf->size) { if (lbuf->len + extra + 1 >= lbuf->size) {
char *new_buf; char *new_buf;
int new_size = lbuf->size; int new_size = lbuf->size;
@@ -74,13 +76,15 @@ sudo_lbuf_expand(struct sudo_lbuf *lbuf, int extra)
new_size += 256; new_size += 256;
} while (lbuf->len + extra + 1 >= new_size); } while (lbuf->len + extra + 1 >= new_size);
if ((new_buf = realloc(lbuf->buf, new_size)) == NULL) { if ((new_buf = realloc(lbuf->buf, new_size)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
lbuf->error = 1; lbuf->error = 1;
return false; debug_return_bool(false);
} }
lbuf->buf = new_buf; lbuf->buf = new_buf;
lbuf->size = new_size; lbuf->size = new_size;
} }
return true; debug_return_bool(true);
} }
/* /*

View File

@@ -393,8 +393,11 @@ sudo_setenv2(const char *var, const char *val, bool dupcheck, bool overwrite)
debug_decl(sudo_setenv2, SUDOERS_DEBUG_ENV) debug_decl(sudo_setenv2, SUDOERS_DEBUG_ENV)
esize = strlen(var) + 1 + strlen(val) + 1; esize = strlen(var) + 1 + strlen(val) + 1;
if ((estring = malloc(esize)) == NULL) if ((estring = malloc(esize)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_int(-1); debug_return_int(-1);
}
/* Build environment string and insert it. */ /* Build environment string and insert it. */
if (strlcpy(estring, var, esize) >= esize || if (strlcpy(estring, var, esize) >= esize ||
@@ -851,6 +854,8 @@ rebuild_env(void)
env.old_envp = env.envp; env.old_envp = env.envp;
env.envp = reallocarray(NULL, env.env_size, sizeof(char *)); env.envp = reallocarray(NULL, env.env_size, sizeof(char *));
if (env.envp == NULL) { if (env.envp == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
env.env_size = 0; env.env_size = 0;
goto bad; goto bad;
} }
@@ -1178,6 +1183,8 @@ read_env_file(const char *path, int overwrite)
} }
if ((cp = malloc(var_len + 1 + val_len + 1)) == NULL) { if ((cp = malloc(var_len + 1 + val_len + 1)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
/* XXX - no undo on failure */ /* XXX - no undo on failure */
rval = false; rval = false;
break; break;
@@ -1208,6 +1215,8 @@ init_envtables(void)
for (p = initial_badenv_table; *p; p++) { for (p = initial_badenv_table; *p; p++) {
cur = calloc(1, sizeof(struct list_member)); cur = calloc(1, sizeof(struct list_member));
if (cur == NULL || (cur->value = strdup(*p)) == NULL) { if (cur == NULL || (cur->value = strdup(*p)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
free(cur); free(cur);
debug_return_bool(false); debug_return_bool(false);
} }
@@ -1218,6 +1227,8 @@ init_envtables(void)
for (p = initial_checkenv_table; *p; p++) { for (p = initial_checkenv_table; *p; p++) {
cur = calloc(1, sizeof(struct list_member)); cur = calloc(1, sizeof(struct list_member));
if (cur == NULL || (cur->value = strdup(*p)) == NULL) { if (cur == NULL || (cur->value = strdup(*p)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
free(cur); free(cur);
debug_return_bool(false); debug_return_bool(false);
} }
@@ -1228,6 +1239,8 @@ init_envtables(void)
for (p = initial_keepenv_table; *p; p++) { for (p = initial_keepenv_table; *p; p++) {
cur = calloc(1, sizeof(struct list_member)); cur = calloc(1, sizeof(struct list_member));
if (cur == NULL || (cur->value = strdup(*p)) == NULL) { if (cur == NULL || (cur->value = strdup(*p)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
free(cur); free(cur);
debug_return_bool(false); debug_return_bool(false);
} }

View File

@@ -740,16 +740,19 @@ new_default(char *var, char *val, int op)
struct defaults *d; struct defaults *d;
debug_decl(new_default, SUDOERS_DEBUG_PARSER) debug_decl(new_default, SUDOERS_DEBUG_PARSER)
d = calloc(1, sizeof(struct defaults)); if ((d = calloc(1, sizeof(struct defaults))) == NULL) {
if (d != NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
d->var = var; "unable to allocate memory");
d->val = val; debug_return_ptr(NULL);
/* d->type = 0; */
d->op = op;
/* d->binding = NULL */
HLTQ_INIT(d, entries);
} }
d->var = var;
d->val = val;
/* d->type = 0; */
d->op = op;
/* d->binding = NULL */
HLTQ_INIT(d, entries);
debug_return_ptr(d); debug_return_ptr(d);
} }
@@ -759,13 +762,16 @@ new_member(char *name, int type)
struct member *m; struct member *m;
debug_decl(new_member, SUDOERS_DEBUG_PARSER) debug_decl(new_member, SUDOERS_DEBUG_PARSER)
m = calloc(1, sizeof(struct member)); if ((m = calloc(1, sizeof(struct member))) == NULL) {
if (m != NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
m->name = name; "unable to allocate memory");
m->type = type; debug_return_ptr(NULL);
HLTQ_INIT(m, entries);
} }
m->name = name;
m->type = type;
HLTQ_INIT(m, entries);
debug_return_ptr(m); debug_return_ptr(m);
} }
@@ -775,14 +781,19 @@ new_digest(int digest_type, const char *digest_str)
struct sudo_digest *dig; struct sudo_digest *dig;
debug_decl(new_digest, SUDOERS_DEBUG_PARSER) debug_decl(new_digest, SUDOERS_DEBUG_PARSER)
dig = malloc(sizeof(*dig)); if ((dig = malloc(sizeof(*dig))) == NULL) {
if (dig != NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
dig->digest_type = digest_type; "unable to allocate memory");
dig->digest_str = strdup(digest_str); debug_return_ptr(NULL);
if (dig->digest_str == NULL) { }
free(dig);
dig = NULL; dig->digest_type = digest_type;
} dig->digest_str = strdup(digest_str);
if (dig->digest_str == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
free(dig);
dig = NULL;
} }
debug_return_ptr(dig); debug_return_ptr(dig);
@@ -804,8 +815,11 @@ add_defaults(int type, struct member *bmem, struct defaults *defs)
/* /*
* We use a single binding for each entry in defs. * We use a single binding for each entry in defs.
*/ */
if ((binding = malloc(sizeof(*binding))) == NULL) if ((binding = malloc(sizeof(*binding))) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_bool(false); debug_return_bool(false);
}
if (bmem != NULL) if (bmem != NULL)
HLTQ_TO_TAILQ(binding, bmem, entries); HLTQ_TO_TAILQ(binding, bmem, entries);
else else
@@ -835,8 +849,11 @@ add_userspec(struct member *members, struct privilege *privs)
struct userspec *u; struct userspec *u;
debug_decl(add_userspec, SUDOERS_DEBUG_PARSER) debug_decl(add_userspec, SUDOERS_DEBUG_PARSER)
if ((u = calloc(1, sizeof(*u))) == NULL) if ((u = calloc(1, sizeof(*u))) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_bool(false); debug_return_bool(false);
}
HLTQ_TO_TAILQ(&u->users, members, entries); HLTQ_TO_TAILQ(&u->users, members, entries);
HLTQ_TO_TAILQ(&u->privileges, privs, entries); HLTQ_TO_TAILQ(&u->privileges, privs, entries);
TAILQ_INSERT_TAIL(&userspecs, u, entries); TAILQ_INSERT_TAIL(&userspecs, u, entries);
@@ -983,7 +1000,7 @@ init_parser(const char *path, bool quiet)
debug_return_bool(rval); debug_return_bool(rval);
} }
#line 934 "gram.c" #line 951 "gram.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */ /* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || defined(__STDC__) #if defined(__cplusplus) || defined(__STDC__)
static int yygrowstack(void) static int yygrowstack(void)
@@ -2063,7 +2080,7 @@ case 113:
} }
} }
break; break;
#line 2014 "gram.c" #line 2031 "gram.c"
} }
yyssp -= yym; yyssp -= yym;
yystate = *yyssp; yystate = *yyssp;

View File

@@ -885,16 +885,19 @@ new_default(char *var, char *val, int op)
struct defaults *d; struct defaults *d;
debug_decl(new_default, SUDOERS_DEBUG_PARSER) debug_decl(new_default, SUDOERS_DEBUG_PARSER)
d = calloc(1, sizeof(struct defaults)); if ((d = calloc(1, sizeof(struct defaults))) == NULL) {
if (d != NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
d->var = var; "unable to allocate memory");
d->val = val; debug_return_ptr(NULL);
/* d->type = 0; */
d->op = op;
/* d->binding = NULL */
HLTQ_INIT(d, entries);
} }
d->var = var;
d->val = val;
/* d->type = 0; */
d->op = op;
/* d->binding = NULL */
HLTQ_INIT(d, entries);
debug_return_ptr(d); debug_return_ptr(d);
} }
@@ -904,13 +907,16 @@ new_member(char *name, int type)
struct member *m; struct member *m;
debug_decl(new_member, SUDOERS_DEBUG_PARSER) debug_decl(new_member, SUDOERS_DEBUG_PARSER)
m = calloc(1, sizeof(struct member)); if ((m = calloc(1, sizeof(struct member))) == NULL) {
if (m != NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
m->name = name; "unable to allocate memory");
m->type = type; debug_return_ptr(NULL);
HLTQ_INIT(m, entries);
} }
m->name = name;
m->type = type;
HLTQ_INIT(m, entries);
debug_return_ptr(m); debug_return_ptr(m);
} }
@@ -920,14 +926,19 @@ new_digest(int digest_type, const char *digest_str)
struct sudo_digest *dig; struct sudo_digest *dig;
debug_decl(new_digest, SUDOERS_DEBUG_PARSER) debug_decl(new_digest, SUDOERS_DEBUG_PARSER)
dig = malloc(sizeof(*dig)); if ((dig = malloc(sizeof(*dig))) == NULL) {
if (dig != NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
dig->digest_type = digest_type; "unable to allocate memory");
dig->digest_str = strdup(digest_str); debug_return_ptr(NULL);
if (dig->digest_str == NULL) { }
free(dig);
dig = NULL; dig->digest_type = digest_type;
} dig->digest_str = strdup(digest_str);
if (dig->digest_str == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
free(dig);
dig = NULL;
} }
debug_return_ptr(dig); debug_return_ptr(dig);
@@ -949,8 +960,11 @@ add_defaults(int type, struct member *bmem, struct defaults *defs)
/* /*
* We use a single binding for each entry in defs. * We use a single binding for each entry in defs.
*/ */
if ((binding = malloc(sizeof(*binding))) == NULL) if ((binding = malloc(sizeof(*binding))) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_bool(false); debug_return_bool(false);
}
if (bmem != NULL) if (bmem != NULL)
HLTQ_TO_TAILQ(binding, bmem, entries); HLTQ_TO_TAILQ(binding, bmem, entries);
else else
@@ -980,8 +994,11 @@ add_userspec(struct member *members, struct privilege *privs)
struct userspec *u; struct userspec *u;
debug_decl(add_userspec, SUDOERS_DEBUG_PARSER) debug_decl(add_userspec, SUDOERS_DEBUG_PARSER)
if ((u = calloc(1, sizeof(*u))) == NULL) if ((u = calloc(1, sizeof(*u))) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_bool(false); debug_return_bool(false);
}
HLTQ_TO_TAILQ(&u->users, members, entries); HLTQ_TO_TAILQ(&u->users, members, entries);
HLTQ_TO_TAILQ(&u->privileges, privs, entries); HLTQ_TO_TAILQ(&u->privileges, privs, entries);
TAILQ_INSERT_TAIL(&userspecs, u, entries); TAILQ_INSERT_TAIL(&userspecs, u, entries);

View File

@@ -66,8 +66,11 @@ set_interfaces(const char *ai)
*mask++ = '\0'; *mask++ = '\0';
/* Parse addr and store in list. */ /* Parse addr and store in list. */
if ((ifp = calloc(1, sizeof(*ifp))) == NULL) if ((ifp = calloc(1, sizeof(*ifp))) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
goto done; goto done;
}
if (strchr(addr, ':')) { if (strchr(addr, ':')) {
/* IPv6 */ /* IPv6 */
#ifdef HAVE_STRUCT_IN6_ADDR #ifdef HAVE_STRUCT_IN6_ADDR

View File

@@ -932,6 +932,10 @@ sudo_getdomainname(void)
} }
} }
} }
} else {
/* XXX - want to pass error back to caller */
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
} }
initialized = true; initialized = true;
} }

View File

@@ -109,8 +109,11 @@ sudo_make_pwitem(uid_t uid, const char *name)
total += strlen(name) + 1; total += strlen(name) + 1;
/* Allocate space for struct item, struct passwd and the strings. */ /* Allocate space for struct item, struct passwd and the strings. */
if ((pwitem = calloc(1, total)) == NULL) if ((pwitem = calloc(1, total)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_ptr(NULL); debug_return_ptr(NULL);
}
newpw = &pwitem->pw; newpw = &pwitem->pw;
/* /*
@@ -181,8 +184,11 @@ sudo_make_gritem(gid_t gid, const char *name)
if (name != NULL) if (name != NULL)
total += strlen(name) + 1; total += strlen(name) + 1;
if ((gritem = calloc(1, total)) == NULL) if ((gritem = calloc(1, total)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_ptr(NULL); debug_return_ptr(NULL);
}
/* /*
* Copy in group contents and make strings relative to space * Copy in group contents and make strings relative to space
@@ -245,21 +251,30 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1,
if (sudo_user.max_groups > 0) { if (sudo_user.max_groups > 0) {
ngids = sudo_user.max_groups; ngids = sudo_user.max_groups;
gids = reallocarray(NULL, ngids, sizeof(GETGROUPS_T)); gids = reallocarray(NULL, ngids, sizeof(GETGROUPS_T));
if (gids == NULL) if (gids == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_ptr(NULL); debug_return_ptr(NULL);
}
(void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids); (void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids);
} else { } else {
ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2; ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2;
if (ngids < 0) if (ngids < 0)
ngids = NGROUPS_MAX * 2; ngids = NGROUPS_MAX * 2;
gids = reallocarray(NULL, ngids, sizeof(GETGROUPS_T)); gids = reallocarray(NULL, ngids, sizeof(GETGROUPS_T));
if (gids == NULL) if (gids == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_ptr(NULL); debug_return_ptr(NULL);
}
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) { if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) {
free(gids); free(gids);
gids = reallocarray(NULL, ngids, sizeof(GETGROUPS_T)); gids = reallocarray(NULL, ngids, sizeof(GETGROUPS_T));
if (gids == NULL) if (gids == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_ptr(NULL); debug_return_ptr(NULL);
}
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;
} }
@@ -286,6 +301,8 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1,
again: again:
if ((grlitem = calloc(1, total)) == NULL) { if ((grlitem = calloc(1, total)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
free(gids); free(gids);
debug_return_ptr(NULL); debug_return_ptr(NULL);
} }

View File

@@ -84,26 +84,30 @@ rbcreate(int (*compar)(const void *, const void*))
struct rbtree *tree; struct rbtree *tree;
debug_decl(rbcreate, SUDOERS_DEBUG_RBTREE) debug_decl(rbcreate, SUDOERS_DEBUG_RBTREE)
if ((tree = malloc(sizeof(*tree))) != NULL) { if ((tree = malloc(sizeof(*tree))) == NULL) {
tree->compar = compar; sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
/* debug_return_ptr(NULL);
* We use a self-referencing sentinel node called nil to simplify the
* code by avoiding the need to check for NULL pointers.
*/
tree->nil.left = tree->nil.right = tree->nil.parent = &tree->nil;
tree->nil.color = black;
tree->nil.data = NULL;
/*
* Similarly, the fake root node keeps us from having to worry
* about splitting the root.
*/
tree->root.left = tree->root.right = tree->root.parent = &tree->nil;
tree->root.color = black;
tree->root.data = NULL;
} }
tree->compar = compar;
/*
* We use a self-referencing sentinel node called nil to simplify the
* code by avoiding the need to check for NULL pointers.
*/
tree->nil.left = tree->nil.right = tree->nil.parent = &tree->nil;
tree->nil.color = black;
tree->nil.data = NULL;
/*
* Similarly, the fake root node keeps us from having to worry
* about splitting the root.
*/
tree->root.left = tree->root.right = tree->root.parent = &tree->nil;
tree->root.color = black;
tree->root.data = NULL;
debug_return_ptr(tree); debug_return_ptr(tree);
} }
@@ -184,8 +188,11 @@ rbinsert(struct rbtree *tree, void *data, struct rbnode **existing)
} }
node = malloc(sizeof(*node)); node = malloc(sizeof(*node));
if (node == NULL) if (node == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_int(-1); debug_return_int(-1);
}
node->data = data; node->data = data;
node->left = node->right = rbnil(tree); node->left = node->right = rbnil(tree);
node->parent = parent; node->parent = parent;

View File

@@ -131,8 +131,11 @@ register_hook_internal(struct sudo_hook_list *head,
struct sudo_hook_entry *hook; struct sudo_hook_entry *hook;
debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS) debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS)
if ((hook = calloc(1, sizeof(*hook))) == NULL) if ((hook = calloc(1, sizeof(*hook))) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_int(-1); debug_return_int(-1);
}
hook->u.generic_fn = hook_fn; hook->u.generic_fn = hook_fn;
hook->closure = closure; hook->closure = closure;
SLIST_INSERT_HEAD(head, hook, entries); SLIST_INSERT_HEAD(head, hook, entries);

View File

@@ -144,8 +144,11 @@ get_net_ifs(char **addrinfo)
if (num_interfaces == 0) if (num_interfaces == 0)
debug_return_int(0); debug_return_int(0);
ailen = num_interfaces * 2 * INET6_ADDRSTRLEN; ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;
if ((cp = malloc(ailen)) == NULL) if ((cp = malloc(ailen)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_int(-1); debug_return_int(-1);
}
*addrinfo = cp; *addrinfo = cp;
/* Store the IP addr/netmask pairs. */ /* Store the IP addr/netmask pairs. */
@@ -236,6 +239,8 @@ get_net_ifs(char **addrinfo)
*/ */
for (;;) { for (;;) {
if ((ifconf_buf = malloc(buflen)) == NULL) { if ((ifconf_buf = malloc(buflen)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
num_interfaces = -1; num_interfaces = -1;
goto done; goto done;
} }
@@ -264,6 +269,8 @@ get_net_ifs(char **addrinfo)
goto done; goto done;
ailen = n * 2 * INET6_ADDRSTRLEN; ailen = n * 2 * INET6_ADDRSTRLEN;
if ((cp = malloc(ailen)) == NULL) { if ((cp = malloc(ailen)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
num_interfaces = -1; num_interfaces = -1;
goto done; goto done;
} }

View File

@@ -458,8 +458,11 @@ get_user_info(struct user_details *ud)
/* XXX - bound check number of entries */ /* XXX - bound check number of entries */
user_info = reallocarray(NULL, 32, sizeof(char *)); user_info = reallocarray(NULL, 32, sizeof(char *));
if (user_info == NULL) if (user_info == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
goto bad; goto bad;
}
ud->pid = getpid(); ud->pid = getpid();
ud->ppid = getppid(); ud->ppid = getppid();
@@ -753,7 +756,7 @@ command_info_to_details(char * const info[], struct command_details *details)
#endif #endif
details->pw = getpwuid(details->euid); details->pw = getpwuid(details->euid);
if (details->pw != NULL && (details->pw = pw_dup(details->pw)) == NULL) if (details->pw != NULL && (details->pw = pw_dup(details->pw)) == NULL)
sudo_fatal(NULL); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
#ifdef HAVE_SETAUTHDB #ifdef HAVE_SETAUTHDB
aix_restoreauthdb(); aix_restoreauthdb();
#endif #endif
@@ -1135,15 +1138,15 @@ format_plugin_settings(struct plugin_container *plugin,
plugin_settings = ps = plugin_settings = ps =
reallocarray(NULL, plugin_settings_size, sizeof(char *)); reallocarray(NULL, plugin_settings_size, sizeof(char *));
if (plugin_settings == NULL) if (plugin_settings == NULL)
sudo_fatal(NULL); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
if ((*ps++ = sudo_new_key_val("plugin_path", plugin->path)) == NULL) if ((*ps++ = sudo_new_key_val("plugin_path", plugin->path)) == NULL)
sudo_fatal(NULL); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
for (setting = sudo_settings; setting->name != NULL; setting++) { for (setting = sudo_settings; setting->name != NULL; setting++) {
if (setting->value != NULL) { if (setting->value != NULL) {
sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s", sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
setting->name, setting->value); setting->name, setting->value);
if ((*ps++ = sudo_new_key_val(setting->name, setting->value)) == NULL) if ((*ps++ = sudo_new_key_val(setting->name, setting->value)) == NULL)
sudo_fatal(NULL); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
} }
} }
if (plugin->debug_files != NULL) { if (plugin->debug_files != NULL) {
@@ -1151,7 +1154,7 @@ format_plugin_settings(struct plugin_container *plugin,
/* XXX - quote filename? */ /* XXX - quote filename? */
if (asprintf(ps++, "debug_flags=%s %s", debug_file->debug_file, if (asprintf(ps++, "debug_flags=%s %s", debug_file->debug_file,
debug_file->debug_flags) == -1) debug_file->debug_flags) == -1)
sudo_fatal(NULL); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
} }
} }
*ps = NULL; *ps = NULL;