Use ecalloc() when allocating structs.

This commit is contained in:
Todd C. Miller
2012-03-19 11:24:24 -04:00
parent dbbb48c45f
commit 55d1a1a79d
15 changed files with 81 additions and 94 deletions

View File

@@ -242,12 +242,12 @@ set_plugin(const char *entry)
pathlen = strlen(path); pathlen = strlen(path);
} }
info = emalloc(sizeof(*info)); info = ecalloc(1, sizeof(*info));
info->symbol_name = estrndup(name, namelen); info->symbol_name = estrndup(name, namelen);
info->path = estrndup(path, pathlen); info->path = estrndup(path, pathlen);
info->options = options; info->options = options;
info->prev = info; info->prev = info;
info->next = NULL; /* info->next = NULL; */
tq_append(&sudo_conf_data.plugins, info); tq_append(&sudo_conf_data.plugins, info);
return true; return true;
@@ -350,21 +350,21 @@ sudo_conf_read(void)
done: done:
if (tq_empty(&sudo_conf_data.plugins)) { if (tq_empty(&sudo_conf_data.plugins)) {
/* Default policy plugin */ /* Default policy plugin */
info = emalloc(sizeof(*info)); info = ecalloc(1, sizeof(*info));
info->symbol_name = "sudoers_policy"; info->symbol_name = "sudoers_policy";
info->path = SUDOERS_PLUGIN; info->path = SUDOERS_PLUGIN;
info->options = NULL; /* info->options = NULL; */
info->prev = info; info->prev = info;
info->next = NULL; /* info->next = NULL; */
tq_append(&sudo_conf_data.plugins, info); tq_append(&sudo_conf_data.plugins, info);
/* Default I/O plugin */ /* Default I/O plugin */
info = emalloc(sizeof(*info)); info = ecalloc(1, sizeof(*info));
info->symbol_name = "sudoers_io"; info->symbol_name = "sudoers_io";
info->path = SUDOERS_PLUGIN; info->path = SUDOERS_PLUGIN;
info->options = NULL; /* info->options = NULL; */
info->prev = info; info->prev = info;
info->next = NULL; /* info->next = NULL; */
tq_append(&sudo_conf_data.plugins, info); tq_append(&sudo_conf_data.plugins, info);
} }
} }

View File

@@ -116,10 +116,10 @@ alias_add(char *name, int type, struct member *members)
struct alias *a; struct alias *a;
debug_decl(alias_add, SUDO_DEBUG_ALIAS) debug_decl(alias_add, SUDO_DEBUG_ALIAS)
a = emalloc(sizeof(*a)); a = ecalloc(1, sizeof(*a));
a->name = name; a->name = name;
a->type = type; a->type = type;
a->seqno = 0; /* a->seqno = 0; */
list2tq(&a->members, members); list2tq(&a->members, members);
if (rbinsert(aliases, a)) { if (rbinsert(aliases, a)) {
snprintf(errbuf, sizeof(errbuf), _("Alias `%s' already defined"), name); snprintf(errbuf, sizeof(errbuf), _("Alias `%s' already defined"), name);

View File

@@ -790,10 +790,8 @@ list_op(char *val, size_t len, struct sudo_defs_types *def, enum list_ops op)
/* Add new node to the head of the list. */ /* Add new node to the head of the list. */
if (op == add) { if (op == add) {
cur = emalloc(sizeof(struct list_member)); cur = ecalloc(1, sizeof(struct list_member));
cur->value = emalloc(len + 1); cur->value = estrndup(val, len);
(void) memcpy(cur->value, val, len);
cur->value[len] = '\0';
cur->next = def->sd_un.list; cur->next = def->sd_un.list;
def->sd_un.list = cur; def->sd_un.list = cur;
} }

View File

@@ -986,7 +986,7 @@ init_envtables(void)
/* Fill in the "env_delete" list. */ /* Fill in the "env_delete" list. */
for (p = initial_badenv_table; *p; p++) { 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->value = estrdup(*p);
cur->next = def_env_delete; cur->next = def_env_delete;
def_env_delete = cur; def_env_delete = cur;
@@ -994,7 +994,7 @@ init_envtables(void)
/* Fill in the "env_check" list. */ /* Fill in the "env_check" list. */
for (p = initial_checkenv_table; *p; p++) { 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->value = estrdup(*p);
cur->next = def_env_check; cur->next = def_env_check;
def_env_check = cur; def_env_check = cur;
@@ -1002,7 +1002,7 @@ init_envtables(void)
/* Fill in the "env_keep" list. */ /* Fill in the "env_keep" list. */
for (p = initial_keepenv_table; *p; p++) { 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->value = estrdup(*p);
cur->next = def_env_keep; cur->next = def_env_keep;
def_env_keep = cur; def_env_keep = cur;

View File

@@ -645,14 +645,14 @@ new_default(char *var, char *val, int op)
struct defaults *d; struct defaults *d;
debug_decl(new_default, SUDO_DEBUG_PARSER) debug_decl(new_default, SUDO_DEBUG_PARSER)
d = emalloc(sizeof(struct defaults)); d = ecalloc(1, sizeof(struct defaults));
d->var = var; d->var = var;
d->val = val; d->val = val;
tq_init(&d->binding); tq_init(&d->binding);
d->type = 0; /* d->type = 0; */
d->op = op; d->op = op;
d->prev = d; d->prev = d;
d->next = NULL; /* d->next = NULL; */
debug_return_ptr(d); debug_return_ptr(d);
} }
@@ -663,11 +663,11 @@ new_member(char *name, int type)
struct member *m; struct member *m;
debug_decl(new_member, SUDO_DEBUG_PARSER) debug_decl(new_member, SUDO_DEBUG_PARSER)
m = emalloc(sizeof(struct member)); m = ecalloc(1, sizeof(struct member));
m->name = name; m->name = name;
m->type = type; m->type = type;
m->prev = m; m->prev = m;
m->next = NULL; /* m->next = NULL; */
debug_return_ptr(m); debug_return_ptr(m);
} }
@@ -712,11 +712,11 @@ add_userspec(struct member *members, struct privilege *privs)
struct userspec *u; struct userspec *u;
debug_decl(add_userspec, SUDO_DEBUG_PARSER) debug_decl(add_userspec, SUDO_DEBUG_PARSER)
u = emalloc(sizeof(*u)); u = ecalloc(1, sizeof(*u));
list2tq(&u->users, members); list2tq(&u->users, members);
list2tq(&u->privileges, privs); list2tq(&u->privileges, privs);
u->prev = u; u->prev = u;
u->next = NULL; /* u->next = NULL; */
tq_append(&userspecs, u); tq_append(&userspecs, u);
debug_return; debug_return;
@@ -1155,11 +1155,11 @@ break;
case 26: case 26:
#line 269 "gram.y" #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->hostlist, yyvsp[-2].member);
list2tq(&p->cmndlist, yyvsp[0].cmndspec); list2tq(&p->cmndlist, yyvsp[0].cmndspec);
p->prev = p; p->prev = p;
p->next = NULL; /* p->next = NULL; */
yyval.privilege = p; yyval.privilege = p;
} }
break; break;
@@ -1243,7 +1243,7 @@ break;
case 36: case 36:
#line 339 "gram.y" #line 339 "gram.y"
{ {
struct cmndspec *cs = emalloc(sizeof(*cs)); struct cmndspec *cs = ecalloc(1, sizeof(*cs));
if (yyvsp[-3].runas != NULL) { if (yyvsp[-3].runas != NULL) {
list2tq(&cs->runasuserlist, yyvsp[-3].runas->runasusers); list2tq(&cs->runasuserlist, yyvsp[-3].runas->runasusers);
list2tq(&cs->runasgrouplist, yyvsp[-3].runas->runasgroups); list2tq(&cs->runasgrouplist, yyvsp[-3].runas->runasgroups);
@@ -1343,15 +1343,15 @@ break;
case 48: case 48:
#line 415 "gram.y" #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->runasusers = yyvsp[0].member;
yyval.runas->runasgroups = NULL; /* $$->runasgroups = NULL; */
} }
break; break;
case 49: case 49:
#line 420 "gram.y" #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->runasusers = yyvsp[-2].member;
yyval.runas->runasgroups = yyvsp[0].member; yyval.runas->runasgroups = yyvsp[0].member;
} }
@@ -1359,8 +1359,8 @@ break;
case 50: case 50:
#line 425 "gram.y" #line 425 "gram.y"
{ {
yyval.runas = emalloc(sizeof(struct runascontainer)); yyval.runas = ecalloc(1, sizeof(struct runascontainer));
yyval.runas->runasusers = NULL; /* $$->runasusers = NULL; */
yyval.runas->runasgroups = yyvsp[0].member; yyval.runas->runasgroups = yyvsp[0].member;
} }
break; break;
@@ -1446,7 +1446,7 @@ break;
case 64: case 64:
#line 474 "gram.y" #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->cmnd = yyvsp[0].command.cmnd;
c->args = yyvsp[0].command.args; c->args = yyvsp[0].command.args;
yyval.member = new_member((char *)c, COMMAND); yyval.member = new_member((char *)c, COMMAND);

View File

@@ -267,11 +267,11 @@ privileges : privilege
; ;
privilege : hostlist '=' cmndspeclist { privilege : hostlist '=' cmndspeclist {
struct privilege *p = emalloc(sizeof(*p)); struct privilege *p = ecalloc(1, sizeof(*p));
list2tq(&p->hostlist, $1); list2tq(&p->hostlist, $1);
list2tq(&p->cmndlist, $3); list2tq(&p->cmndlist, $3);
p->prev = p; p->prev = p;
p->next = NULL; /* p->next = NULL; */
$$ = p; $$ = p;
} }
; ;
@@ -337,7 +337,7 @@ cmndspeclist : cmndspec
; ;
cmndspec : runasspec selinux cmndtag opcmnd { cmndspec : runasspec selinux cmndtag opcmnd {
struct cmndspec *cs = emalloc(sizeof(*cs)); struct cmndspec *cs = ecalloc(1, sizeof(*cs));
if ($1 != NULL) { if ($1 != NULL) {
list2tq(&cs->runasuserlist, $1->runasusers); list2tq(&cs->runasuserlist, $1->runasusers);
list2tq(&cs->runasgrouplist, $1->runasgroups); list2tq(&cs->runasgrouplist, $1->runasgroups);
@@ -413,18 +413,18 @@ runasspec : /* empty */ {
; ;
runaslist : userlist { runaslist : userlist {
$$ = emalloc(sizeof(struct runascontainer)); $$ = ecalloc(1, sizeof(struct runascontainer));
$$->runasusers = $1; $$->runasusers = $1;
$$->runasgroups = NULL; /* $$->runasgroups = NULL; */
} }
| userlist ':' grouplist { | userlist ':' grouplist {
$$ = emalloc(sizeof(struct runascontainer)); $$ = ecalloc(1, sizeof(struct runascontainer));
$$->runasusers = $1; $$->runasusers = $1;
$$->runasgroups = $3; $$->runasgroups = $3;
} }
| ':' grouplist { | ':' grouplist {
$$ = emalloc(sizeof(struct runascontainer)); $$ = ecalloc(1, sizeof(struct runascontainer));
$$->runasusers = NULL; /* $$->runasusers = NULL; */
$$->runasgroups = $2; $$->runasgroups = $2;
} }
; ;
@@ -472,7 +472,7 @@ cmnd : ALL {
$$ = new_member($1, ALIAS); $$ = new_member($1, ALIAS);
} }
| COMMAND { | COMMAND {
struct sudo_command *c = emalloc(sizeof(*c)); struct sudo_command *c = ecalloc(1, sizeof(*c));
c->cmnd = $1.cmnd; c->cmnd = $1.cmnd;
c->args = $1.args; c->args = $1.args;
$$ = new_member((char *)c, COMMAND); $$ = new_member((char *)c, COMMAND);
@@ -614,14 +614,14 @@ new_default(char *var, char *val, int op)
struct defaults *d; struct defaults *d;
debug_decl(new_default, SUDO_DEBUG_PARSER) debug_decl(new_default, SUDO_DEBUG_PARSER)
d = emalloc(sizeof(struct defaults)); d = ecalloc(1, sizeof(struct defaults));
d->var = var; d->var = var;
d->val = val; d->val = val;
tq_init(&d->binding); tq_init(&d->binding);
d->type = 0; /* d->type = 0; */
d->op = op; d->op = op;
d->prev = d; d->prev = d;
d->next = NULL; /* d->next = NULL; */
debug_return_ptr(d); debug_return_ptr(d);
} }
@@ -632,11 +632,11 @@ new_member(char *name, int type)
struct member *m; struct member *m;
debug_decl(new_member, SUDO_DEBUG_PARSER) debug_decl(new_member, SUDO_DEBUG_PARSER)
m = emalloc(sizeof(struct member)); m = ecalloc(1, sizeof(struct member));
m->name = name; m->name = name;
m->type = type; m->type = type;
m->prev = m; m->prev = m;
m->next = NULL; /* m->next = NULL; */
debug_return_ptr(m); debug_return_ptr(m);
} }
@@ -681,11 +681,11 @@ add_userspec(struct member *members, struct privilege *privs)
struct userspec *u; struct userspec *u;
debug_decl(add_userspec, SUDO_DEBUG_PARSER) debug_decl(add_userspec, SUDO_DEBUG_PARSER)
u = emalloc(sizeof(*u)); u = ecalloc(1, sizeof(*u));
list2tq(&u->users, members); list2tq(&u->users, members);
list2tq(&u->privileges, privs); list2tq(&u->privileges, privs);
u->prev = u; u->prev = u;
u->next = NULL; /* u->next = NULL; */
tq_append(&userspecs, u); tq_append(&userspecs, u);
debug_return; debug_return;

View File

@@ -71,7 +71,7 @@ set_interfaces(const char *ai)
*mask++ = '\0'; *mask++ = '\0';
/* Parse addr and store in list. */ /* Parse addr and store in list. */
ifp = emalloc(sizeof(*ifp)); ifp = ecalloc(1, sizeof(*ifp));
if (strchr(addr, ':')) { if (strchr(addr, ':')) {
/* IPv6 */ /* IPv6 */
#ifdef HAVE_STRUCT_IN6_ADDR #ifdef HAVE_STRUCT_IN6_ADDR

View File

@@ -1984,14 +1984,7 @@ sudo_ldap_result_alloc(void)
struct ldap_result *result; struct ldap_result *result;
debug_decl(sudo_ldap_result_alloc, SUDO_DEBUG_LDAP) debug_decl(sudo_ldap_result_alloc, SUDO_DEBUG_LDAP)
result = emalloc(sizeof(*result)); debug_return_ptr(ecalloc(1, 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);
} }
/* /*
@@ -2030,10 +2023,10 @@ sudo_ldap_result_add_search(struct ldap_result *lres, LDAP *ldap,
struct ldap_search_list *s, *news; struct ldap_search_list *s, *news;
debug_decl(sudo_ldap_result_add_search, SUDO_DEBUG_LDAP) debug_decl(sudo_ldap_result_add_search, SUDO_DEBUG_LDAP)
news = emalloc(sizeof(struct ldap_search_list)); news = ecalloc(1, sizeof(struct ldap_search_list));
news->next = NULL;
news->ldap = ldap; news->ldap = ldap;
news->searchresult = searchresult; news->searchresult = searchresult;
/* news->next = NULL; */
/* Add entry to the end of the chain (XXX - tailq instead?). */ /* Add entry to the end of the chain (XXX - tailq instead?). */
if (lres->searches) { if (lres->searches) {
@@ -2200,11 +2193,11 @@ sudo_ldap_open(struct sudo_nss *nss)
debug_return_int(-1); debug_return_int(-1);
/* Create a handle container. */ /* Create a handle container. */
handle = emalloc(sizeof(struct sudo_ldap_handle)); handle = ecalloc(1, sizeof(struct sudo_ldap_handle));
handle->ld = ld; handle->ld = ld;
handle->result = NULL; /* handle->result = NULL; */
handle->username = NULL; /* handle->username = NULL; */
handle->grlist = NULL; /* handle->grlist = NULL; */
nss->handle = handle; nss->handle = handle;
debug_return_int(0); debug_return_int(0);

View File

@@ -884,7 +884,7 @@ set_cmnd(void)
/* Resolve the path and return. */ /* Resolve the path and return. */
rval = FOUND; rval = FOUND;
user_stat = emalloc(sizeof(struct stat)); user_stat = ecalloc(1, sizeof(struct stat));
/* Default value for cmnd, overridden below. */ /* Default value for cmnd, overridden below. */
if (user_cmnd == NULL) if (user_cmnd == NULL)

View File

@@ -200,7 +200,6 @@ extern time_t get_date(char *);
extern char *get_timestr(time_t, int); extern char *get_timestr(time_t, int);
extern int term_raw(int, int); extern int term_raw(int, int);
extern int term_restore(int, int); extern int term_restore(int, int);
extern void zero_bytes(volatile void *, size_t);
void cleanup(int); void cleanup(int);
static int list_sessions(int, char **, const char *, const char *, const char *); static int list_sessions(int, char **, const char *, const char *, const char *);
@@ -368,7 +367,7 @@ main(int argc, char *argv[])
fclose(lfile); fclose(lfile);
fflush(stdout); fflush(stdout);
zero_bytes(&sa, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND; sa.sa_flags = SA_RESETHAND;
sa.sa_handler = cleanup; sa.sa_handler = cleanup;
@@ -391,8 +390,7 @@ main(int argc, char *argv[])
if (!term_raw(STDIN_FILENO, 1)) if (!term_raw(STDIN_FILENO, 1))
error(1, _("unable to set tty to raw mode")); error(1, _("unable to set tty to raw mode"));
} }
fdsw = (fd_set *)emalloc2(howmany(STDOUT_FILENO + 1, NFDBITS), fdsw = ecalloc(howmany(STDOUT_FILENO + 1, NFDBITS), sizeof(fd_mask));
sizeof(fd_mask));
/* /*
* Timing file consists of line of the format: "%f %d\n" * Timing file consists of line of the format: "%f %d\n"
@@ -590,11 +588,11 @@ parse_expr(struct search_node **headp, char *argv[])
} }
/* Allocate new search node */ /* Allocate new search node */
newsn = emalloc(sizeof(*newsn)); newsn = ecalloc(1, sizeof(*newsn));
newsn->next = NULL;
newsn->type = type; newsn->type = type;
newsn->or = or; newsn->or = or;
newsn->negated = not; newsn->negated = not;
/* newsn->next = NULL; */
if (type == ST_EXPR) { if (type == ST_EXPR) {
av += parse_expr(&newsn->u.expr, av + 1); av += parse_expr(&newsn->u.expr, av + 1);
} else { } else {
@@ -871,8 +869,7 @@ check_input(int ttyfd, double *speed)
ssize_t n; ssize_t n;
debug_decl(check_input, SUDO_DEBUG_UTIL) 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 (;;) { for (;;) {
FD_SET(ttyfd, fdsr); FD_SET(ttyfd, fdsr);
tv.tv_sec = 0; tv.tv_sec = 0;

View File

@@ -880,13 +880,13 @@ open_sudoers(const char *path, bool doedit, bool *keepopen)
break; break;
} }
if (entry == NULL) { if (entry == NULL) {
entry = emalloc(sizeof(*entry)); entry = ecalloc(1, sizeof(*entry));
entry->path = estrdup(path); entry->path = estrdup(path);
entry->modified = 0; /* entry->modified = 0; */
entry->prev = entry; entry->prev = entry;
entry->next = NULL; /* entry->next = NULL; */
entry->fd = open(entry->path, open_flags, SUDOERS_MODE); entry->fd = open(entry->path, open_flags, SUDOERS_MODE);
entry->tpath = NULL; /* entry->tpath = NULL; */
entry->doedit = doedit; entry->doedit = doedit;
if (entry->fd == -1) { if (entry->fd == -1) {
warning("%s", entry->path); warning("%s", entry->path);

View File

@@ -320,11 +320,11 @@ sudo_execute(struct command_details *details, struct command_status *cstat)
* In the event loop we pass input from user tty to master * In the event loop we pass input from user tty to master
* and pass output from master to stdout and IO plugin. * and pass output from master to stdout and IO plugin.
*/ */
fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); fdsr = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
fdsw = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); fdsw = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
for (;;) { for (;;) {
zero_bytes(fdsw, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); memset(fdsw, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
zero_bytes(fdsr, 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(signal_pipe[0], fdsr);
FD_SET(sv[0], fdsr); FD_SET(sv[0], fdsr);
@@ -582,9 +582,9 @@ schedule_signal(int signo)
sudo_debug_printf(SUDO_DEBUG_DIAG, "forwarding signal %d to child", signo); 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->prev = sigfwd;
sigfwd->next = NULL; /* sigfwd->next = NULL; */
sigfwd->signo = signo; sigfwd->signo = signo;
tq_append(&sigfwd_list, sigfwd); tq_append(&sigfwd_list, sigfwd);

View File

@@ -405,7 +405,7 @@ io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int),
struct io_buffer *iob; struct io_buffer *iob;
debug_decl(io_buf_new, SUDO_DEBUG_EXEC); debug_decl(io_buf_new, SUDO_DEBUG_EXEC);
iob = emalloc(sizeof(*iob)); iob = ecalloc(1, sizeof(*iob));
zero_bytes(iob, sizeof(*iob)); zero_bytes(iob, sizeof(*iob));
iob->rfd = rfd; iob->rfd = rfd;
iob->wfd = wfd; iob->wfd = wfd;
@@ -989,9 +989,8 @@ exec_monitor(struct command_details *details, int backchannel)
/* Wait for errno on pipe, signal on backchannel or for SIGCHLD */ /* Wait for errno on pipe, signal on backchannel or for SIGCHLD */
maxfd = MAX(MAX(errpipe[0], signal_pipe[0]), backchannel); maxfd = MAX(MAX(errpipe[0], signal_pipe[0]), backchannel);
fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); fdsr = ecalloc(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
zero_bytes(fdsr, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); memset(&cstat, 0, sizeof(cstat));
zero_bytes(&cstat, sizeof(cstat));
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
for (;;) { for (;;) {
@@ -1102,11 +1101,11 @@ flush_output(void)
if (maxfd == -1) if (maxfd == -1)
debug_return; debug_return;
fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); fdsr = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
fdsw = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); fdsw = emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
for (;;) { for (;;) {
zero_bytes(fdsw, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); memset(fdsw, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
zero_bytes(fdsr, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); memset(fdsr, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
nwriters = 0; nwriters = 0;
for (iob = iobufs; iob; iob = iob->next) { for (iob = iobufs; iob; iob = iob->next) {

View File

@@ -171,7 +171,7 @@ register_hook_internal(struct sudo_hook_list **head,
struct sudo_hook_list *hook; struct sudo_hook_list *hook;
debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS) debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS)
hook = emalloc(sizeof(*hook)); hook = ecalloc(1, sizeof(*hook));
hook->u.generic_fn = hook_fn; hook->u.generic_fn = hook_fn;
hook->closure = closure; hook->closure = closure;
hook->next = *head; hook->next = *head;

View File

@@ -134,9 +134,9 @@ sudo_load_plugins(struct plugin_container *policy_plugin,
policy_plugin->options = info->options; policy_plugin->options = info->options;
policy_plugin->u.generic = plugin; policy_plugin->u.generic = plugin;
} else if (plugin->type == SUDO_IO_PLUGIN) { } else if (plugin->type == SUDO_IO_PLUGIN) {
container = emalloc(sizeof(*container)); container = ecalloc(1, sizeof(*container));
container->prev = container; container->prev = container;
container->next = NULL; /* container->next = NULL; */
container->handle = handle; container->handle = handle;
container->name = info->symbol_name; container->name = info->symbol_name;
container->options = info->options; container->options = info->options;