pathlen = strlen(path);
}
- info = emalloc(sizeof(*info));
+ info = ecalloc(1, sizeof(*info));
info->symbol_name = estrndup(name, namelen);
info->path = estrndup(path, pathlen);
info->options = options;
info->prev = info;
- info->next = NULL;
+ /* info->next = NULL; */
tq_append(&sudo_conf_data.plugins, info);
return true;
done:
if (tq_empty(&sudo_conf_data.plugins)) {
/* Default policy plugin */
- info = emalloc(sizeof(*info));
+ info = ecalloc(1, sizeof(*info));
info->symbol_name = "sudoers_policy";
info->path = SUDOERS_PLUGIN;
- info->options = NULL;
+ /* info->options = NULL; */
info->prev = info;
- info->next = NULL;
+ /* info->next = NULL; */
tq_append(&sudo_conf_data.plugins, info);
/* Default I/O plugin */
- info = emalloc(sizeof(*info));
+ info = ecalloc(1, sizeof(*info));
info->symbol_name = "sudoers_io";
info->path = SUDOERS_PLUGIN;
- info->options = NULL;
+ /* info->options = NULL; */
info->prev = info;
- info->next = NULL;
+ /* info->next = NULL; */
tq_append(&sudo_conf_data.plugins, info);
}
}
struct alias *a;
debug_decl(alias_add, SUDO_DEBUG_ALIAS)
- a = emalloc(sizeof(*a));
+ a = ecalloc(1, sizeof(*a));
a->name = name;
a->type = type;
- a->seqno = 0;
+ /* a->seqno = 0; */
list2tq(&a->members, members);
if (rbinsert(aliases, a)) {
snprintf(errbuf, sizeof(errbuf), _("Alias `%s' already defined"), name);
/* Add new node to the head of the list. */
if (op == add) {
- cur = emalloc(sizeof(struct list_member));
- cur->value = emalloc(len + 1);
- (void) memcpy(cur->value, val, len);
- cur->value[len] = '\0';
+ cur = ecalloc(1, sizeof(struct list_member));
+ cur->value = estrndup(val, len);
cur->next = def->sd_un.list;
def->sd_un.list = cur;
}
/* Fill in the "env_delete" list. */
for (p = initial_badenv_table; *p; p++) {
- cur = emalloc(sizeof(struct list_member));
+ cur = ecalloc(1, sizeof(struct list_member));
cur->value = estrdup(*p);
cur->next = def_env_delete;
def_env_delete = cur;
/* Fill in the "env_check" list. */
for (p = initial_checkenv_table; *p; p++) {
- cur = emalloc(sizeof(struct list_member));
+ cur = ecalloc(1, sizeof(struct list_member));
cur->value = estrdup(*p);
cur->next = def_env_check;
def_env_check = cur;
/* Fill in the "env_keep" list. */
for (p = initial_keepenv_table; *p; p++) {
- cur = emalloc(sizeof(struct list_member));
+ cur = ecalloc(1, sizeof(struct list_member));
cur->value = estrdup(*p);
cur->next = def_env_keep;
def_env_keep = cur;
struct defaults *d;
debug_decl(new_default, SUDO_DEBUG_PARSER)
- d = emalloc(sizeof(struct defaults));
+ d = ecalloc(1, sizeof(struct defaults));
d->var = var;
d->val = val;
tq_init(&d->binding);
- d->type = 0;
+ /* d->type = 0; */
d->op = op;
d->prev = d;
- d->next = NULL;
+ /* d->next = NULL; */
debug_return_ptr(d);
}
struct member *m;
debug_decl(new_member, SUDO_DEBUG_PARSER)
- m = emalloc(sizeof(struct member));
+ m = ecalloc(1, sizeof(struct member));
m->name = name;
m->type = type;
m->prev = m;
- m->next = NULL;
+ /* m->next = NULL; */
debug_return_ptr(m);
}
struct userspec *u;
debug_decl(add_userspec, SUDO_DEBUG_PARSER)
- u = emalloc(sizeof(*u));
+ u = ecalloc(1, sizeof(*u));
list2tq(&u->users, members);
list2tq(&u->privileges, privs);
u->prev = u;
- u->next = NULL;
+ /* u->next = NULL; */
tq_append(&userspecs, u);
debug_return;
case 26:
#line 269 "gram.y"
{
- struct privilege *p = emalloc(sizeof(*p));
+ struct privilege *p = ecalloc(1, sizeof(*p));
list2tq(&p->hostlist, yyvsp[-2].member);
list2tq(&p->cmndlist, yyvsp[0].cmndspec);
p->prev = p;
- p->next = NULL;
+ /* p->next = NULL; */
yyval.privilege = p;
}
break;
case 36:
#line 339 "gram.y"
{
- struct cmndspec *cs = emalloc(sizeof(*cs));
+ struct cmndspec *cs = ecalloc(1, sizeof(*cs));
if (yyvsp[-3].runas != NULL) {
list2tq(&cs->runasuserlist, yyvsp[-3].runas->runasusers);
list2tq(&cs->runasgrouplist, yyvsp[-3].runas->runasgroups);
case 48:
#line 415 "gram.y"
{
- yyval.runas = emalloc(sizeof(struct runascontainer));
+ yyval.runas = ecalloc(1, sizeof(struct runascontainer));
yyval.runas->runasusers = yyvsp[0].member;
- yyval.runas->runasgroups = NULL;
+ /* $$->runasgroups = NULL; */
}
break;
case 49:
#line 420 "gram.y"
{
- yyval.runas = emalloc(sizeof(struct runascontainer));
+ yyval.runas = ecalloc(1, sizeof(struct runascontainer));
yyval.runas->runasusers = yyvsp[-2].member;
yyval.runas->runasgroups = yyvsp[0].member;
}
case 50:
#line 425 "gram.y"
{
- yyval.runas = emalloc(sizeof(struct runascontainer));
- yyval.runas->runasusers = NULL;
+ yyval.runas = ecalloc(1, sizeof(struct runascontainer));
+ /* $$->runasusers = NULL; */
yyval.runas->runasgroups = yyvsp[0].member;
}
break;
case 64:
#line 474 "gram.y"
{
- struct sudo_command *c = emalloc(sizeof(*c));
+ struct sudo_command *c = ecalloc(1, sizeof(*c));
c->cmnd = yyvsp[0].command.cmnd;
c->args = yyvsp[0].command.args;
yyval.member = new_member((char *)c, COMMAND);
;
privilege : hostlist '=' cmndspeclist {
- struct privilege *p = emalloc(sizeof(*p));
+ struct privilege *p = ecalloc(1, sizeof(*p));
list2tq(&p->hostlist, $1);
list2tq(&p->cmndlist, $3);
p->prev = p;
- p->next = NULL;
+ /* p->next = NULL; */
$$ = p;
}
;
;
cmndspec : runasspec selinux cmndtag opcmnd {
- struct cmndspec *cs = emalloc(sizeof(*cs));
+ struct cmndspec *cs = ecalloc(1, sizeof(*cs));
if ($1 != NULL) {
list2tq(&cs->runasuserlist, $1->runasusers);
list2tq(&cs->runasgrouplist, $1->runasgroups);
;
runaslist : userlist {
- $$ = emalloc(sizeof(struct runascontainer));
+ $$ = ecalloc(1, sizeof(struct runascontainer));
$$->runasusers = $1;
- $$->runasgroups = NULL;
+ /* $$->runasgroups = NULL; */
}
| userlist ':' grouplist {
- $$ = emalloc(sizeof(struct runascontainer));
+ $$ = ecalloc(1, sizeof(struct runascontainer));
$$->runasusers = $1;
$$->runasgroups = $3;
}
| ':' grouplist {
- $$ = emalloc(sizeof(struct runascontainer));
- $$->runasusers = NULL;
+ $$ = ecalloc(1, sizeof(struct runascontainer));
+ /* $$->runasusers = NULL; */
$$->runasgroups = $2;
}
;
$$ = new_member($1, ALIAS);
}
| COMMAND {
- struct sudo_command *c = emalloc(sizeof(*c));
+ struct sudo_command *c = ecalloc(1, sizeof(*c));
c->cmnd = $1.cmnd;
c->args = $1.args;
$$ = new_member((char *)c, COMMAND);
struct defaults *d;
debug_decl(new_default, SUDO_DEBUG_PARSER)
- d = emalloc(sizeof(struct defaults));
+ d = ecalloc(1, sizeof(struct defaults));
d->var = var;
d->val = val;
tq_init(&d->binding);
- d->type = 0;
+ /* d->type = 0; */
d->op = op;
d->prev = d;
- d->next = NULL;
+ /* d->next = NULL; */
debug_return_ptr(d);
}
struct member *m;
debug_decl(new_member, SUDO_DEBUG_PARSER)
- m = emalloc(sizeof(struct member));
+ m = ecalloc(1, sizeof(struct member));
m->name = name;
m->type = type;
m->prev = m;
- m->next = NULL;
+ /* m->next = NULL; */
debug_return_ptr(m);
}
struct userspec *u;
debug_decl(add_userspec, SUDO_DEBUG_PARSER)
- u = emalloc(sizeof(*u));
+ u = ecalloc(1, sizeof(*u));
list2tq(&u->users, members);
list2tq(&u->privileges, privs);
u->prev = u;
- u->next = NULL;
+ /* u->next = NULL; */
tq_append(&userspecs, u);
debug_return;
*mask++ = '\0';
/* Parse addr and store in list. */
- ifp = emalloc(sizeof(*ifp));
+ ifp = ecalloc(1, sizeof(*ifp));
if (strchr(addr, ':')) {
/* IPv6 */
#ifdef HAVE_STRUCT_IN6_ADDR
struct ldap_result *result;
debug_decl(sudo_ldap_result_alloc, SUDO_DEBUG_LDAP)
- result = emalloc(sizeof(*result));
- result->searches = NULL;
- result->nentries = 0;
- result->entries = NULL;
- result->allocated_entries = 0;
- result->user_matches = false;
- result->host_matches = false;
- debug_return_ptr(result);
+ debug_return_ptr(ecalloc(1, sizeof(*result)));
}
/*
struct ldap_search_list *s, *news;
debug_decl(sudo_ldap_result_add_search, SUDO_DEBUG_LDAP)
- news = emalloc(sizeof(struct ldap_search_list));
- news->next = NULL;
+ news = ecalloc(1, sizeof(struct ldap_search_list));
news->ldap = ldap;
news->searchresult = searchresult;
+ /* news->next = NULL; */
/* Add entry to the end of the chain (XXX - tailq instead?). */
if (lres->searches) {
debug_return_int(-1);
/* Create a handle container. */
- handle = emalloc(sizeof(struct sudo_ldap_handle));
+ handle = ecalloc(1, sizeof(struct sudo_ldap_handle));
handle->ld = ld;
- handle->result = NULL;
- handle->username = NULL;
- handle->grlist = NULL;
+ /* handle->result = NULL; */
+ /* handle->username = NULL; */
+ /* handle->grlist = NULL; */
nss->handle = handle;
debug_return_int(0);
/* Resolve the path and return. */
rval = FOUND;
- user_stat = emalloc(sizeof(struct stat));
+ user_stat = ecalloc(1, sizeof(struct stat));
/* Default value for cmnd, overridden below. */
if (user_cmnd == NULL)
extern char *get_timestr(time_t, int);
extern int term_raw(int, int);
extern int term_restore(int, int);
-extern void zero_bytes(volatile void *, size_t);
void cleanup(int);
static int list_sessions(int, char **, const char *, const char *, const char *);
fclose(lfile);
fflush(stdout);
- zero_bytes(&sa, sizeof(sa));
+ memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND;
sa.sa_handler = cleanup;
if (!term_raw(STDIN_FILENO, 1))
error(1, _("unable to set tty to raw mode"));
}
- fdsw = (fd_set *)emalloc2(howmany(STDOUT_FILENO + 1, NFDBITS),
- sizeof(fd_mask));
+ fdsw = ecalloc(howmany(STDOUT_FILENO + 1, NFDBITS), sizeof(fd_mask));
/*
* Timing file consists of line of the format: "%f %d\n"
}
/* Allocate new search node */
- newsn = emalloc(sizeof(*newsn));
- newsn->next = NULL;
+ newsn = ecalloc(1, sizeof(*newsn));
newsn->type = type;
newsn->or = or;
newsn->negated = not;
+ /* newsn->next = NULL; */
if (type == ST_EXPR) {
av += parse_expr(&newsn->u.expr, av + 1);
} else {
ssize_t n;
debug_decl(check_input, SUDO_DEBUG_UTIL)
- fdsr = (fd_set *)emalloc2(howmany(ttyfd + 1, NFDBITS), sizeof(fd_mask));
-
+ fdsr = ecalloc(howmany(ttyfd + 1, NFDBITS), sizeof(fd_mask));
for (;;) {
FD_SET(ttyfd, fdsr);
tv.tv_sec = 0;
break;
}
if (entry == NULL) {
- entry = emalloc(sizeof(*entry));
+ entry = ecalloc(1, sizeof(*entry));
entry->path = estrdup(path);
- entry->modified = 0;
+ /* entry->modified = 0; */
entry->prev = entry;
- entry->next = NULL;
+ /* entry->next = NULL; */
entry->fd = open(entry->path, open_flags, SUDOERS_MODE);
- entry->tpath = NULL;
+ /* entry->tpath = NULL; */
entry->doedit = doedit;
if (entry->fd == -1) {
warning("%s", entry->path);
* In the event loop we pass input from user tty to master
* and pass output from master to stdout and IO plugin.
*/
- fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
- fdsw = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
+ fdsr = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
+ fdsw = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
for (;;) {
- zero_bytes(fdsw, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
- zero_bytes(fdsr, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
+ memset(fdsw, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
+ memset(fdsr, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
FD_SET(signal_pipe[0], fdsr);
FD_SET(sv[0], fdsr);
sudo_debug_printf(SUDO_DEBUG_DIAG, "forwarding signal %d to child", signo);
- sigfwd = emalloc(sizeof(*sigfwd));
+ sigfwd = ecalloc(1, sizeof(*sigfwd));
sigfwd->prev = sigfwd;
- sigfwd->next = NULL;
+ /* sigfwd->next = NULL; */
sigfwd->signo = signo;
tq_append(&sigfwd_list, sigfwd);
struct io_buffer *iob;
debug_decl(io_buf_new, SUDO_DEBUG_EXEC);
- iob = emalloc(sizeof(*iob));
+ iob = ecalloc(1, sizeof(*iob));
zero_bytes(iob, sizeof(*iob));
iob->rfd = rfd;
iob->wfd = wfd;
/* Wait for errno on pipe, signal on backchannel or for SIGCHLD */
maxfd = MAX(MAX(errpipe[0], signal_pipe[0]), backchannel);
- fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
- zero_bytes(fdsr, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
- zero_bytes(&cstat, sizeof(cstat));
+ fdsr = ecalloc(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
+ memset(&cstat, 0, sizeof(cstat));
tv.tv_sec = 0;
tv.tv_usec = 0;
for (;;) {
if (maxfd == -1)
debug_return;
- fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
- fdsw = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
+ fdsr = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
+ fdsw = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
for (;;) {
- zero_bytes(fdsw, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
- zero_bytes(fdsr, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
+ memset(fdsw, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
+ memset(fdsr, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
nwriters = 0;
for (iob = iobufs; iob; iob = iob->next) {
struct sudo_hook_list *hook;
debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS)
- hook = emalloc(sizeof(*hook));
+ hook = ecalloc(1, sizeof(*hook));
hook->u.generic_fn = hook_fn;
hook->closure = closure;
hook->next = *head;
policy_plugin->options = info->options;
policy_plugin->u.generic = plugin;
} else if (plugin->type == SUDO_IO_PLUGIN) {
- container = emalloc(sizeof(*container));
+ container = ecalloc(1, sizeof(*container));
container->prev = container;
- container->next = NULL;
+ /* container->next = NULL; */
container->handle = handle;
container->name = info->symbol_name;
container->options = info->options;