Use non-exiting allocators in the parser (much of it already did).

This commit is contained in:
Todd C. Miller
2015-05-27 10:36:03 -06:00
parent 6b7be032af
commit 4da9e10971
6 changed files with 658 additions and 288 deletions

View File

@@ -127,7 +127,11 @@ alias_add(char *name, int type, struct member *members)
struct alias *a; struct alias *a;
debug_decl(alias_add, SUDOERS_DEBUG_ALIAS) debug_decl(alias_add, SUDOERS_DEBUG_ALIAS)
a = sudo_ecalloc(1, sizeof(*a)); a = calloc(1, sizeof(*a));
if (a == NULL) {
strlcpy(errbuf, N_("unable to allocate memory"), sizeof(errbuf));
debug_return_str(errbuf);
}
a->name = name; a->name = name;
a->type = type; a->type = type;
/* a->used = false; */ /* a->used = false; */

File diff suppressed because it is too large Load Diff

View File

@@ -71,8 +71,8 @@ struct userspec_list userspecs = TAILQ_HEAD_INITIALIZER(userspecs);
/* /*
* Local protoypes * Local protoypes
*/ */
static void add_defaults(int, struct member *, struct defaults *); static bool add_defaults(int, struct member *, struct defaults *);
static void add_userspec(struct member *, struct privilege *); static bool add_userspec(struct member *, struct privilege *);
static struct defaults *new_default(char *, char *, int); static struct defaults *new_default(char *, char *, int);
static struct member *new_member(char *, int); static struct member *new_member(char *, int);
static struct sudo_digest *new_digest(int, const char *); static struct sudo_digest *new_digest(int, const char *);
@@ -185,7 +185,10 @@ entry : COMMENT {
yyerrok; yyerrok;
} }
| userlist privileges { | userlist privileges {
add_userspec($1, $2); if (!add_userspec($1, $2)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| USERALIAS useraliases { | USERALIAS useraliases {
; ;
@@ -200,19 +203,34 @@ entry : COMMENT {
; ;
} }
| DEFAULTS defaults_list { | DEFAULTS defaults_list {
add_defaults(DEFAULTS, NULL, $2); if (!add_defaults(DEFAULTS, NULL, $2)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFAULTS_USER userlist defaults_list { | DEFAULTS_USER userlist defaults_list {
add_defaults(DEFAULTS_USER, $2, $3); if (!add_defaults(DEFAULTS_USER, $2, $3)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFAULTS_RUNAS userlist defaults_list { | DEFAULTS_RUNAS userlist defaults_list {
add_defaults(DEFAULTS_RUNAS, $2, $3); if (!add_defaults(DEFAULTS_RUNAS, $2, $3)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFAULTS_HOST hostlist defaults_list { | DEFAULTS_HOST hostlist defaults_list {
add_defaults(DEFAULTS_HOST, $2, $3); if (!add_defaults(DEFAULTS_HOST, $2, $3)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFAULTS_CMND cmndlist defaults_list { | DEFAULTS_CMND cmndlist defaults_list {
add_defaults(DEFAULTS_CMND, $2, $3); if (!add_defaults(DEFAULTS_CMND, $2, $3)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -225,18 +243,38 @@ defaults_list : defaults_entry
defaults_entry : DEFVAR { defaults_entry : DEFVAR {
$$ = new_default($1, NULL, true); $$ = new_default($1, NULL, true);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| '!' DEFVAR { | '!' DEFVAR {
$$ = new_default($2, NULL, false); $$ = new_default($2, NULL, false);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFVAR '=' WORD { | DEFVAR '=' WORD {
$$ = new_default($1, $3, true); $$ = new_default($1, $3, true);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFVAR '+' WORD { | DEFVAR '+' WORD {
$$ = new_default($1, $3, '+'); $$ = new_default($1, $3, '+');
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| DEFVAR '-' WORD { | DEFVAR '-' WORD {
$$ = new_default($1, $3, '-'); $$ = new_default($1, $3, '-');
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -248,7 +286,11 @@ privileges : privilege
; ;
privilege : hostlist '=' cmndspeclist { privilege : hostlist '=' cmndspeclist {
struct privilege *p = sudo_ecalloc(1, sizeof(*p)); struct privilege *p = calloc(1, sizeof(*p));
if (p == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
HLTQ_TO_TAILQ(&p->hostlist, $1, entries); HLTQ_TO_TAILQ(&p->hostlist, $1, entries);
HLTQ_TO_TAILQ(&p->cmndlist, $3, entries); HLTQ_TO_TAILQ(&p->cmndlist, $3, entries);
HLTQ_INIT(p, entries); HLTQ_INIT(p, entries);
@@ -268,18 +310,38 @@ ophost : host {
host : ALIAS { host : ALIAS {
$$ = new_member($1, ALIAS); $$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| ALL { | ALL {
$$ = new_member(NULL, ALL); $$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| NETGROUP { | NETGROUP {
$$ = new_member($1, NETGROUP); $$ = new_member($1, NETGROUP);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| NTWKADDR { | NTWKADDR {
$$ = new_member($1, NTWKADDR); $$ = new_member($1, NTWKADDR);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| WORD { | WORD {
$$ = new_member($1, WORD); $$ = new_member($1, WORD);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -328,21 +390,33 @@ cmndspeclist : cmndspec
; ;
cmndspec : runasspec selinux solarisprivs cmndtag digcmnd { cmndspec : runasspec selinux solarisprivs cmndtag digcmnd {
struct cmndspec *cs = sudo_ecalloc(1, sizeof(*cs)); struct cmndspec *cs = calloc(1, sizeof(*cs));
if (cs == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
if ($1 != NULL) { if ($1 != NULL) {
if ($1->runasusers != NULL) { if ($1->runasusers != NULL) {
cs->runasuserlist = cs->runasuserlist =
sudo_emalloc(sizeof(*cs->runasuserlist)); malloc(sizeof(*cs->runasuserlist));
if (cs->runasuserlist == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
HLTQ_TO_TAILQ(cs->runasuserlist, HLTQ_TO_TAILQ(cs->runasuserlist,
$1->runasusers, entries); $1->runasusers, entries);
} }
if ($1->runasgroups != NULL) { if ($1->runasgroups != NULL) {
cs->runasgrouplist = cs->runasgrouplist =
sudo_emalloc(sizeof(*cs->runasgrouplist)); malloc(sizeof(*cs->runasgrouplist));
if (cs->runasgrouplist == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
HLTQ_TO_TAILQ(cs->runasgrouplist, HLTQ_TO_TAILQ(cs->runasgrouplist,
$1->runasgroups, entries); $1->runasgroups, entries);
} }
sudo_efree($1); free($1);
} }
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
cs->role = $2.role; cs->role = $2.role;
@@ -365,15 +439,31 @@ cmndspec : runasspec selinux solarisprivs cmndtag digcmnd {
digest : SHA224_TOK ':' DIGEST { digest : SHA224_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA224, $3); $$ = new_digest(SUDO_DIGEST_SHA224, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| SHA256_TOK ':' DIGEST { | SHA256_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA256, $3); $$ = new_digest(SUDO_DIGEST_SHA256, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| SHA384_TOK ':' DIGEST { | SHA384_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA384, $3); $$ = new_digest(SUDO_DIGEST_SHA384, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| SHA512_TOK ':' DIGEST { | SHA512_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA512, $3); $$ = new_digest(SUDO_DIGEST_SHA512, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -473,29 +563,61 @@ runasspec : /* empty */ {
; ;
runaslist : /* empty */ { runaslist : /* empty */ {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer)); $$ = calloc(1, sizeof(struct runascontainer));
$$->runasusers = new_member(NULL, MYSELF); if ($$ != NULL) {
/* $$->runasgroups = NULL; */ $$->runasusers = new_member(NULL, MYSELF);
/* $$->runasgroups = NULL; */
if ($$->runasusers == NULL) {
free($$);
$$ = NULL;
}
}
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| userlist { | userlist {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer)); $$ = calloc(1, sizeof(struct runascontainer));
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
$$->runasusers = $1; $$->runasusers = $1;
/* $$->runasgroups = NULL; */ /* $$->runasgroups = NULL; */
} }
| userlist ':' grouplist { | userlist ':' grouplist {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer)); $$ = calloc(1, sizeof(struct runascontainer));
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
$$->runasusers = $1; $$->runasusers = $1;
$$->runasgroups = $3; $$->runasgroups = $3;
} }
| ':' grouplist { | ':' grouplist {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer)); $$ = calloc(1, sizeof(struct runascontainer));
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
/* $$->runasusers = NULL; */ /* $$->runasusers = NULL; */
$$->runasgroups = $2; $$->runasgroups = $2;
} }
| ':' { | ':' {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer)); $$ = calloc(1, sizeof(struct runascontainer));
$$->runasusers = new_member(NULL, MYSELF); if ($$ != NULL) {
/* $$->runasgroups = NULL; */ $$->runasusers = new_member(NULL, MYSELF);
/* $$->runasgroups = NULL; */
if ($$->runasusers == NULL) {
free($$);
$$ = NULL;
}
}
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -543,15 +665,32 @@ cmndtag : /* empty */ {
cmnd : ALL { cmnd : ALL {
$$ = new_member(NULL, ALL); $$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| ALIAS { | ALIAS {
$$ = new_member($1, ALIAS); $$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| COMMAND { | COMMAND {
struct sudo_command *c = sudo_ecalloc(1, sizeof(*c)); struct sudo_command *c = calloc(1, sizeof(*c));
if (c == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
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);
if ($$ == NULL) {
free(c);
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -640,18 +779,38 @@ opuser : user {
user : ALIAS { user : ALIAS {
$$ = new_member($1, ALIAS); $$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| ALL { | ALL {
$$ = new_member(NULL, ALL); $$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| NETGROUP { | NETGROUP {
$$ = new_member($1, NETGROUP); $$ = new_member($1, NETGROUP);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| USERGROUP { | USERGROUP {
$$ = new_member($1, USERGROUP); $$ = new_member($1, USERGROUP);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| WORD { | WORD {
$$ = new_member($1, WORD); $$ = new_member($1, WORD);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -674,12 +833,24 @@ opgroup : group {
group : ALIAS { group : ALIAS {
$$ = new_member($1, ALIAS); $$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| ALL { | ALL {
$$ = new_member(NULL, ALL); $$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
| WORD { | WORD {
$$ = new_member($1, WORD); $$ = new_member($1, WORD);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
} }
; ;
@@ -696,7 +867,7 @@ sudoerserror(const char *s)
/* Save the line the first error occurred on. */ /* Save the line the first error occurred on. */
if (errorlineno == -1) { if (errorlineno == -1) {
errorlineno = sudolineno; errorlineno = sudolineno;
errorfile = sudo_estrdup(sudoers); errorfile = sudoers;
} }
if (sudoers_warnings && s != NULL) { if (sudoers_warnings && s != NULL) {
LEXTRACE("<*> "); LEXTRACE("<*> ");
@@ -722,13 +893,15 @@ 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 = sudo_ecalloc(1, sizeof(struct defaults)); d = calloc(1, sizeof(struct defaults));
d->var = var; if (d != NULL) {
d->val = val; d->var = var;
/* d->type = 0; */ d->val = val;
d->op = op; /* d->type = 0; */
/* d->binding = NULL */ d->op = op;
HLTQ_INIT(d, entries); /* d->binding = NULL */
HLTQ_INIT(d, entries);
}
debug_return_ptr(d); debug_return_ptr(d);
} }
@@ -739,10 +912,12 @@ 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 = sudo_ecalloc(1, sizeof(struct member)); m = calloc(1, sizeof(struct member));
m->name = name; if (m != NULL) {
m->type = type; m->name = name;
HLTQ_INIT(m, entries); m->type = type;
HLTQ_INIT(m, entries);
}
debug_return_ptr(m); debug_return_ptr(m);
} }
@@ -753,9 +928,15 @@ 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 = sudo_emalloc(sizeof(*dig)); dig = malloc(sizeof(*dig));
dig->digest_type = digest_type; if (dig != NULL) {
dig->digest_str = sudo_estrdup(digest_str); dig->digest_type = digest_type;
dig->digest_str = strdup(digest_str);
if (dig->digest_str == NULL) {
free(dig);
dig = NULL;
}
}
debug_return_ptr(dig); debug_return_ptr(dig);
} }
@@ -765,7 +946,7 @@ new_digest(int digest_type, const char *digest_str)
* The binding, if non-NULL, specifies a list of hosts, users, or * The binding, if non-NULL, specifies a list of hosts, users, or
* runas users the entries apply to (specified by the type). * runas users the entries apply to (specified by the type).
*/ */
static void static bool
add_defaults(int type, struct member *bmem, struct defaults *defs) add_defaults(int type, struct member *bmem, struct defaults *defs)
{ {
struct defaults *d; struct defaults *d;
@@ -776,7 +957,8 @@ 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.
*/ */
binding = sudo_emalloc(sizeof(*binding)); if ((binding = malloc(sizeof(*binding))) == NULL)
debug_return_bool(false);
if (bmem != NULL) if (bmem != NULL)
HLTQ_TO_TAILQ(binding, bmem, entries); HLTQ_TO_TAILQ(binding, bmem, entries);
else else
@@ -793,25 +975,26 @@ add_defaults(int type, struct member *bmem, struct defaults *defs)
TAILQ_CONCAT_HLTQ(&defaults, defs, entries); TAILQ_CONCAT_HLTQ(&defaults, defs, entries);
} }
debug_return; debug_return_bool(true);
} }
/* /*
* Allocate a new struct userspec, populate it, and insert it at the * Allocate a new struct userspec, populate it, and insert it at the
* end of the userspecs list. * end of the userspecs list.
*/ */
static void static bool
add_userspec(struct member *members, struct privilege *privs) 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)
u = sudo_ecalloc(1, sizeof(*u)); if ((u = calloc(1, sizeof(*u))) == NULL)
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);
debug_return; debug_return_bool(true);
} }
/* /*
@@ -832,8 +1015,8 @@ init_parser(const char *path, bool quiet)
struct privilege *priv, *priv_next; struct privilege *priv, *priv_next;
TAILQ_FOREACH_SAFE(m, &us->users, entries, m_next) { TAILQ_FOREACH_SAFE(m, &us->users, entries, m_next) {
sudo_efree(m->name); free(m->name);
sudo_efree(m); free(m);
} }
TAILQ_FOREACH_SAFE(priv, &us->privileges, entries, priv_next) { TAILQ_FOREACH_SAFE(priv, &us->privileges, entries, priv_next) {
struct member_list *runasuserlist = NULL, *runasgrouplist = NULL; struct member_list *runasuserlist = NULL, *runasgrouplist = NULL;
@@ -846,62 +1029,62 @@ init_parser(const char *path, bool quiet)
#endif /* HAVE_PRIV_SET */ #endif /* HAVE_PRIV_SET */
TAILQ_FOREACH_SAFE(m, &priv->hostlist, entries, m_next) { TAILQ_FOREACH_SAFE(m, &priv->hostlist, entries, m_next) {
sudo_efree(m->name); free(m->name);
sudo_efree(m); free(m);
} }
TAILQ_FOREACH_SAFE(cs, &priv->cmndlist, entries, cs_next) { TAILQ_FOREACH_SAFE(cs, &priv->cmndlist, entries, cs_next) {
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
/* Only free the first instance of a role/type. */ /* Only free the first instance of a role/type. */
if (cs->role != role) { if (cs->role != role) {
role = cs->role; role = cs->role;
sudo_efree(cs->role); free(cs->role);
} }
if (cs->type != type) { if (cs->type != type) {
type = cs->type; type = cs->type;
sudo_efree(cs->type); free(cs->type);
} }
#endif /* HAVE_SELINUX */ #endif /* HAVE_SELINUX */
#ifdef HAVE_PRIV_SET #ifdef HAVE_PRIV_SET
/* Only free the first instance of privs/limitprivs. */ /* Only free the first instance of privs/limitprivs. */
if (cs->privs != privs) { if (cs->privs != privs) {
privs = cs->privs; privs = cs->privs;
sudo_efree(cs->privs); free(cs->privs);
} }
if (cs->limitprivs != limitprivs) { if (cs->limitprivs != limitprivs) {
limitprivs = cs->limitprivs; limitprivs = cs->limitprivs;
sudo_efree(cs->limitprivs); free(cs->limitprivs);
} }
#endif /* HAVE_PRIV_SET */ #endif /* HAVE_PRIV_SET */
/* Only free the first instance of runas user/group lists. */ /* Only free the first instance of runas user/group lists. */
if (cs->runasuserlist && cs->runasuserlist != runasuserlist) { if (cs->runasuserlist && cs->runasuserlist != runasuserlist) {
runasuserlist = cs->runasuserlist; runasuserlist = cs->runasuserlist;
TAILQ_FOREACH_SAFE(m, runasuserlist, entries, m_next) { TAILQ_FOREACH_SAFE(m, runasuserlist, entries, m_next) {
sudo_efree(m->name); free(m->name);
sudo_efree(m); free(m);
} }
sudo_efree(runasuserlist); free(runasuserlist);
} }
if (cs->runasgrouplist && cs->runasgrouplist != runasgrouplist) { if (cs->runasgrouplist && cs->runasgrouplist != runasgrouplist) {
runasgrouplist = cs->runasgrouplist; runasgrouplist = cs->runasgrouplist;
TAILQ_FOREACH_SAFE(m, runasgrouplist, entries, m_next) { TAILQ_FOREACH_SAFE(m, runasgrouplist, entries, m_next) {
sudo_efree(m->name); free(m->name);
sudo_efree(m); free(m);
} }
sudo_efree(runasgrouplist); free(runasgrouplist);
} }
if (cs->cmnd->type == COMMAND) { if (cs->cmnd->type == COMMAND) {
struct sudo_command *c = struct sudo_command *c =
(struct sudo_command *) cs->cmnd->name; (struct sudo_command *) cs->cmnd->name;
sudo_efree(c->cmnd); free(c->cmnd);
sudo_efree(c->args); free(c->args);
} }
sudo_efree(cs->cmnd->name); free(cs->cmnd->name);
sudo_efree(cs->cmnd); free(cs->cmnd);
sudo_efree(cs); free(cs);
} }
sudo_efree(priv); free(priv);
} }
sudo_efree(us); free(us);
} }
TAILQ_INIT(&userspecs); TAILQ_INIT(&userspecs);
@@ -915,17 +1098,17 @@ init_parser(const char *path, bool quiet)
if (m->type == COMMAND) { if (m->type == COMMAND) {
struct sudo_command *c = struct sudo_command *c =
(struct sudo_command *) m->name; (struct sudo_command *) m->name;
sudo_efree(c->cmnd); free(c->cmnd);
sudo_efree(c->args); free(c->args);
} }
sudo_efree(m->name); free(m->name);
sudo_efree(m); free(m);
} }
sudo_efree(d->binding); free(d->binding);
} }
sudo_efree(d->var); free(d->var);
sudo_efree(d->val); free(d->val);
sudo_efree(d); free(d);
} }
TAILQ_INIT(&defaults); TAILQ_INIT(&defaults);

View File

@@ -4078,12 +4078,12 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
if (asprintf(&path, "%s/%s", dirpath, dent->d_name) == -1) if (asprintf(&path, "%s/%s", dirpath, dent->d_name) == -1)
goto bad; goto bad;
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) { if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
sudo_efree(path); free(path);
continue; continue;
} }
pl = malloc(sizeof(*pl)); pl = malloc(sizeof(*pl));
if (pl == NULL) { if (pl == NULL) {
sudo_efree(path); free(path);
goto bad; goto bad;
} }
pl->path = path; pl->path = path;
@@ -4092,8 +4092,8 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
max_paths <<= 1; max_paths <<= 1;
tmp = reallocarray(paths, max_paths, sizeof(*paths)); tmp = reallocarray(paths, max_paths, sizeof(*paths));
if (tmp == NULL) { if (tmp == NULL) {
sudo_efree(path); free(path);
sudo_efree(pl); free(pl);
goto bad; goto bad;
} }
paths = tmp; paths = tmp;
@@ -4102,7 +4102,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
} }
closedir(dir); closedir(dir);
if (count == 0) { if (count == 0) {
sudo_efree(paths); free(paths);
paths = NULL; paths = NULL;
} }
*pathsp = paths; *pathsp = paths;
@@ -4111,10 +4111,10 @@ bad:
if (dir != NULL) if (dir != NULL)
closedir(dir); closedir(dir);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
sudo_efree(paths[i]->path); free(paths[i]->path);
sudo_efree(paths[i]); free(paths[i]);
} }
sudo_efree(paths); free(paths);
debug_return_int(-1); debug_return_int(-1);
} }
@@ -4138,7 +4138,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
SLIST_INSERT_HEAD(&stack->more, paths[i], entries); SLIST_INSERT_HEAD(&stack->more, paths[i], entries);
} }
sudo_efree(paths); free(paths);
} }
debug_return_int(count); debug_return_int(count);
@@ -4161,15 +4161,15 @@ init_lexer(void)
idepth--; idepth--;
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) { while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
SLIST_REMOVE_HEAD(&istack[idepth].more, entries); SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
sudo_efree(pl->path); free(pl->path);
sudo_efree(pl); free(pl);
} }
sudo_efree(istack[idepth].path); free(istack[idepth].path);
if (idepth && !istack[idepth].keepopen) if (idepth && !istack[idepth].keepopen)
fclose(istack[idepth].bs->yy_input_file); fclose(istack[idepth].bs->yy_input_file);
sudoers_delete_buffer(istack[idepth].bs); sudoers_delete_buffer(istack[idepth].bs);
} }
sudo_efree(istack); free(istack);
istack = NULL; istack = NULL;
istacksize = idepth = 0; istacksize = idepth = 0;
sudolineno = 1; sudolineno = 1;
@@ -4246,20 +4246,20 @@ push_include_int(char *path, bool isdir)
count = switch_dir(&istack[idepth], path); count = switch_dir(&istack[idepth], path);
if (count <= 0) { if (count <= 0) {
/* switch_dir() called sudoerserror() for us */ /* switch_dir() called sudoerserror() for us */
sudo_efree(path); free(path);
debug_return_bool(count ? false : true); debug_return_bool(count ? false : true);
} }
/* Parse the first dir entry we can open, leave the rest for later. */ /* Parse the first dir entry we can open, leave the rest for later. */
do { do {
sudo_efree(path); free(path);
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) { if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
/* Unable to open any files in include dir, not an error. */ /* Unable to open any files in include dir, not an error. */
debug_return_bool(true); debug_return_bool(true);
} }
SLIST_REMOVE_HEAD(&istack[idepth].more, entries); SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
path = pl->path; path = pl->path;
sudo_efree(pl); free(pl);
} while ((fp = open_sudoers(path, false, &keepopen)) == NULL); } while ((fp = open_sudoers(path, false, &keepopen)) == NULL);
} else { } else {
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) { if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
@@ -4299,22 +4299,22 @@ pop_include(void)
SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries); SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries);
fp = open_sudoers(pl->path, false, &keepopen); fp = open_sudoers(pl->path, false, &keepopen);
if (fp != NULL) { if (fp != NULL) {
sudo_efree(sudoers); free(sudoers);
sudoers = pl->path; sudoers = pl->path;
sudolineno = 1; sudolineno = 1;
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE)); sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
sudo_efree(pl); free(pl);
break; break;
} }
/* Unable to open path in include dir, go to next one. */ /* Unable to open path in include dir, go to next one. */
sudo_efree(pl->path); free(pl->path);
sudo_efree(pl); free(pl);
} }
/* If no path list, just pop the last dir on the stack. */ /* If no path list, just pop the last dir on the stack. */
if (pl == NULL) { if (pl == NULL) {
idepth--; idepth--;
sudoers_switch_to_buffer(istack[idepth].bs); sudoers_switch_to_buffer(istack[idepth].bs);
sudo_efree(sudoers); free(sudoers);
sudoers = istack[idepth].path; sudoers = istack[idepth].path;
sudolineno = istack[idepth].lineno; sudolineno = istack[idepth].lineno;
keepopen = istack[idepth].keepopen; keepopen = istack[idepth].keepopen;

View File

@@ -807,12 +807,12 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
if (asprintf(&path, "%s/%s", dirpath, dent->d_name) == -1) if (asprintf(&path, "%s/%s", dirpath, dent->d_name) == -1)
goto bad; goto bad;
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) { if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
sudo_efree(path); free(path);
continue; continue;
} }
pl = malloc(sizeof(*pl)); pl = malloc(sizeof(*pl));
if (pl == NULL) { if (pl == NULL) {
sudo_efree(path); free(path);
goto bad; goto bad;
} }
pl->path = path; pl->path = path;
@@ -821,8 +821,8 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
max_paths <<= 1; max_paths <<= 1;
tmp = reallocarray(paths, max_paths, sizeof(*paths)); tmp = reallocarray(paths, max_paths, sizeof(*paths));
if (tmp == NULL) { if (tmp == NULL) {
sudo_efree(path); free(path);
sudo_efree(pl); free(pl);
goto bad; goto bad;
} }
paths = tmp; paths = tmp;
@@ -831,7 +831,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
} }
closedir(dir); closedir(dir);
if (count == 0) { if (count == 0) {
sudo_efree(paths); free(paths);
paths = NULL; paths = NULL;
} }
*pathsp = paths; *pathsp = paths;
@@ -840,10 +840,10 @@ bad:
if (dir != NULL) if (dir != NULL)
closedir(dir); closedir(dir);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
sudo_efree(paths[i]->path); free(paths[i]->path);
sudo_efree(paths[i]); free(paths[i]);
} }
sudo_efree(paths); free(paths);
debug_return_int(-1); debug_return_int(-1);
} }
@@ -867,7 +867,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
SLIST_INSERT_HEAD(&stack->more, paths[i], entries); SLIST_INSERT_HEAD(&stack->more, paths[i], entries);
} }
sudo_efree(paths); free(paths);
} }
debug_return_int(count); debug_return_int(count);
@@ -890,15 +890,15 @@ init_lexer(void)
idepth--; idepth--;
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) { while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
SLIST_REMOVE_HEAD(&istack[idepth].more, entries); SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
sudo_efree(pl->path); free(pl->path);
sudo_efree(pl); free(pl);
} }
sudo_efree(istack[idepth].path); free(istack[idepth].path);
if (idepth && !istack[idepth].keepopen) if (idepth && !istack[idepth].keepopen)
fclose(istack[idepth].bs->yy_input_file); fclose(istack[idepth].bs->yy_input_file);
sudoers_delete_buffer(istack[idepth].bs); sudoers_delete_buffer(istack[idepth].bs);
} }
sudo_efree(istack); free(istack);
istack = NULL; istack = NULL;
istacksize = idepth = 0; istacksize = idepth = 0;
sudolineno = 1; sudolineno = 1;
@@ -975,20 +975,20 @@ push_include_int(char *path, bool isdir)
count = switch_dir(&istack[idepth], path); count = switch_dir(&istack[idepth], path);
if (count <= 0) { if (count <= 0) {
/* switch_dir() called sudoerserror() for us */ /* switch_dir() called sudoerserror() for us */
sudo_efree(path); free(path);
debug_return_bool(count ? false : true); debug_return_bool(count ? false : true);
} }
/* Parse the first dir entry we can open, leave the rest for later. */ /* Parse the first dir entry we can open, leave the rest for later. */
do { do {
sudo_efree(path); free(path);
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) { if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
/* Unable to open any files in include dir, not an error. */ /* Unable to open any files in include dir, not an error. */
debug_return_bool(true); debug_return_bool(true);
} }
SLIST_REMOVE_HEAD(&istack[idepth].more, entries); SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
path = pl->path; path = pl->path;
sudo_efree(pl); free(pl);
} while ((fp = open_sudoers(path, false, &keepopen)) == NULL); } while ((fp = open_sudoers(path, false, &keepopen)) == NULL);
} else { } else {
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) { if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
@@ -1028,22 +1028,22 @@ pop_include(void)
SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries); SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries);
fp = open_sudoers(pl->path, false, &keepopen); fp = open_sudoers(pl->path, false, &keepopen);
if (fp != NULL) { if (fp != NULL) {
sudo_efree(sudoers); free(sudoers);
sudoers = pl->path; sudoers = pl->path;
sudolineno = 1; sudolineno = 1;
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE)); sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
sudo_efree(pl); free(pl);
break; break;
} }
/* Unable to open path in include dir, go to next one. */ /* Unable to open path in include dir, go to next one. */
sudo_efree(pl->path); free(pl->path);
sudo_efree(pl); free(pl);
} }
/* If no path list, just pop the last dir on the stack. */ /* If no path list, just pop the last dir on the stack. */
if (pl == NULL) { if (pl == NULL) {
idepth--; idepth--;
sudoers_switch_to_buffer(istack[idepth].bs); sudoers_switch_to_buffer(istack[idepth].bs);
sudo_efree(sudoers); free(sudoers);
sudoers = istack[idepth].path; sudoers = istack[idepth].path;
sudolineno = istack[idepth].lineno; sudolineno = istack[idepth].lineno;
keepopen = istack[idepth].keepopen; keepopen = istack[idepth].keepopen;

View File

@@ -157,7 +157,7 @@ fill_args(const char *s, int len, int addspace)
p = sudoerslval.command.args ? p = sudoerslval.command.args ?
realloc(sudoerslval.command.args, arg_size) : malloc(arg_size); realloc(sudoerslval.command.args, arg_size) : malloc(arg_size);
if (p == NULL) { if (p == NULL) {
sudo_efree(sudoerslval.command.args); free(sudoerslval.command.args);
sudo_warn(NULL); sudo_warn(NULL);
sudoerserror(NULL); sudoerserror(NULL);
debug_return_bool(false); debug_return_bool(false);