explicit call to sudo_warnx().
static bool
sudo_lbuf_expand(struct sudo_lbuf *lbuf, int extra)
{
+ debug_decl(sudo_lbuf_expand, SUDO_DEBUG_UTIL)
+
if (lbuf->len + extra + 1 >= lbuf->size) {
char *new_buf;
int new_size = lbuf->size;
new_size += 256;
} while (lbuf->len + extra + 1 >= new_size);
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;
- return false;
+ debug_return_bool(false);
}
lbuf->buf = new_buf;
lbuf->size = new_size;
}
- return true;
+ debug_return_bool(true);
}
/*
debug_decl(sudo_setenv2, SUDOERS_DEBUG_ENV)
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);
+ }
/* Build environment string and insert it. */
if (strlcpy(estring, var, esize) >= esize ||
env.old_envp = env.envp;
env.envp = reallocarray(NULL, env.env_size, sizeof(char *));
if (env.envp == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
env.env_size = 0;
goto bad;
}
}
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 */
rval = false;
break;
for (p = initial_badenv_table; *p; p++) {
cur = calloc(1, sizeof(struct list_member));
if (cur == NULL || (cur->value = strdup(*p)) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
free(cur);
debug_return_bool(false);
}
for (p = initial_checkenv_table; *p; p++) {
cur = calloc(1, sizeof(struct list_member));
if (cur == NULL || (cur->value = strdup(*p)) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
free(cur);
debug_return_bool(false);
}
for (p = initial_keepenv_table; *p; p++) {
cur = calloc(1, sizeof(struct list_member));
if (cur == NULL || (cur->value = strdup(*p)) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
free(cur);
debug_return_bool(false);
}
struct defaults *d;
debug_decl(new_default, SUDOERS_DEBUG_PARSER)
- d = calloc(1, sizeof(struct defaults));
- if (d != NULL) {
- d->var = var;
- d->val = val;
- /* d->type = 0; */
- d->op = op;
- /* d->binding = NULL */
- HLTQ_INIT(d, entries);
+ if ((d = calloc(1, sizeof(struct defaults))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(NULL);
}
+ d->var = var;
+ d->val = val;
+ /* d->type = 0; */
+ d->op = op;
+ /* d->binding = NULL */
+ HLTQ_INIT(d, entries);
+
debug_return_ptr(d);
}
struct member *m;
debug_decl(new_member, SUDOERS_DEBUG_PARSER)
- m = calloc(1, sizeof(struct member));
- if (m != NULL) {
- m->name = name;
- m->type = type;
- HLTQ_INIT(m, entries);
+ if ((m = calloc(1, sizeof(struct member))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(NULL);
}
+ m->name = name;
+ m->type = type;
+ HLTQ_INIT(m, entries);
+
debug_return_ptr(m);
}
struct sudo_digest *dig;
debug_decl(new_digest, SUDOERS_DEBUG_PARSER)
- dig = malloc(sizeof(*dig));
- if (dig != NULL) {
- dig->digest_type = digest_type;
- dig->digest_str = strdup(digest_str);
- if (dig->digest_str == NULL) {
- free(dig);
- dig = NULL;
- }
+ if ((dig = malloc(sizeof(*dig))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(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);
/*
* 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);
+ }
if (bmem != NULL)
HLTQ_TO_TAILQ(binding, bmem, entries);
else
struct userspec *u;
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);
+ }
HLTQ_TO_TAILQ(&u->users, members, entries);
HLTQ_TO_TAILQ(&u->privileges, privs, entries);
TAILQ_INSERT_TAIL(&userspecs, u, entries);
debug_return_bool(rval);
}
-#line 934 "gram.c"
+#line 951 "gram.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || defined(__STDC__)
static int yygrowstack(void)
}
}
break;
-#line 2014 "gram.c"
+#line 2031 "gram.c"
}
yyssp -= yym;
yystate = *yyssp;
struct defaults *d;
debug_decl(new_default, SUDOERS_DEBUG_PARSER)
- d = calloc(1, sizeof(struct defaults));
- if (d != NULL) {
- d->var = var;
- d->val = val;
- /* d->type = 0; */
- d->op = op;
- /* d->binding = NULL */
- HLTQ_INIT(d, entries);
+ if ((d = calloc(1, sizeof(struct defaults))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(NULL);
}
+ d->var = var;
+ d->val = val;
+ /* d->type = 0; */
+ d->op = op;
+ /* d->binding = NULL */
+ HLTQ_INIT(d, entries);
+
debug_return_ptr(d);
}
struct member *m;
debug_decl(new_member, SUDOERS_DEBUG_PARSER)
- m = calloc(1, sizeof(struct member));
- if (m != NULL) {
- m->name = name;
- m->type = type;
- HLTQ_INIT(m, entries);
+ if ((m = calloc(1, sizeof(struct member))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(NULL);
}
+ m->name = name;
+ m->type = type;
+ HLTQ_INIT(m, entries);
+
debug_return_ptr(m);
}
struct sudo_digest *dig;
debug_decl(new_digest, SUDOERS_DEBUG_PARSER)
- dig = malloc(sizeof(*dig));
- if (dig != NULL) {
- dig->digest_type = digest_type;
- dig->digest_str = strdup(digest_str);
- if (dig->digest_str == NULL) {
- free(dig);
- dig = NULL;
- }
+ if ((dig = malloc(sizeof(*dig))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(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);
/*
* 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);
+ }
if (bmem != NULL)
HLTQ_TO_TAILQ(binding, bmem, entries);
else
struct userspec *u;
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);
+ }
HLTQ_TO_TAILQ(&u->users, members, entries);
HLTQ_TO_TAILQ(&u->privileges, privs, entries);
TAILQ_INSERT_TAIL(&userspecs, u, entries);
*mask++ = '\0';
/* 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;
+ }
if (strchr(addr, ':')) {
/* IPv6 */
#ifdef HAVE_STRUCT_IN6_ADDR
}
}
}
+ } else {
+ /* XXX - want to pass error back to caller */
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
}
initialized = true;
}
total += strlen(name) + 1;
/* 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);
+ }
newpw = &pwitem->pw;
/*
if (name != NULL)
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);
+ }
/*
* Copy in group contents and make strings relative to space
if (sudo_user.max_groups > 0) {
ngids = sudo_user.max_groups;
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);
+ }
(void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids);
} else {
ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2;
if (ngids < 0)
ngids = NGROUPS_MAX * 2;
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);
+ }
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) {
free(gids);
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);
+ }
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1)
ngids = -1;
}
again:
if ((grlitem = calloc(1, total)) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
free(gids);
debug_return_ptr(NULL);
}
struct rbtree *tree;
debug_decl(rbcreate, SUDOERS_DEBUG_RBTREE)
- if ((tree = malloc(sizeof(*tree))) != 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;
+ if ((tree = malloc(sizeof(*tree))) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
+ debug_return_ptr(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);
}
}
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);
+ }
node->data = data;
node->left = node->right = rbnil(tree);
node->parent = parent;
struct sudo_hook_entry *hook;
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);
+ }
hook->u.generic_fn = hook_fn;
hook->closure = closure;
SLIST_INSERT_HEAD(head, hook, entries);
if (num_interfaces == 0)
debug_return_int(0);
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);
+ }
*addrinfo = cp;
/* Store the IP addr/netmask pairs. */
*/
for (;;) {
if ((ifconf_buf = malloc(buflen)) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
num_interfaces = -1;
goto done;
}
goto done;
ailen = n * 2 * INET6_ADDRSTRLEN;
if ((cp = malloc(ailen)) == NULL) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
+ "unable to allocate memory");
num_interfaces = -1;
goto done;
}
/* XXX - bound check number of entries */
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;
+ }
ud->pid = getpid();
ud->ppid = getppid();
#endif
details->pw = getpwuid(details->euid);
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
aix_restoreauthdb();
#endif
plugin_settings = ps =
reallocarray(NULL, plugin_settings_size, sizeof(char *));
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)
- sudo_fatal(NULL);
+ sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
for (setting = sudo_settings; setting->name != NULL; setting++) {
if (setting->value != NULL) {
sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
setting->name, setting->value);
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) {
/* XXX - quote filename? */
if (asprintf(ps++, "debug_flags=%s %s", debug_file->debug_file,
debug_file->debug_flags) == -1)
- sudo_fatal(NULL);
+ sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
}
}
*ps = NULL;