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;
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->type = type;
/* 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
*/
static void add_defaults(int, struct member *, struct defaults *);
static void add_userspec(struct member *, struct privilege *);
static bool add_defaults(int, struct member *, struct defaults *);
static bool add_userspec(struct member *, struct privilege *);
static struct defaults *new_default(char *, char *, int);
static struct member *new_member(char *, int);
static struct sudo_digest *new_digest(int, const char *);
@@ -185,7 +185,10 @@ entry : COMMENT {
yyerrok;
}
| userlist privileges {
add_userspec($1, $2);
if (!add_userspec($1, $2)) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| USERALIAS useraliases {
;
@@ -200,19 +203,34 @@ entry : COMMENT {
;
}
| 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 {
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 {
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 {
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 {
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 {
$$ = new_default($1, NULL, true);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| '!' DEFVAR {
$$ = new_default($2, NULL, false);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| DEFVAR '=' WORD {
$$ = new_default($1, $3, true);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| DEFVAR '+' WORD {
$$ = new_default($1, $3, '+');
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| DEFVAR '-' WORD {
$$ = new_default($1, $3, '-');
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
;
@@ -248,7 +286,11 @@ privileges : privilege
;
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->cmndlist, $3, entries);
HLTQ_INIT(p, entries);
@@ -268,18 +310,38 @@ ophost : host {
host : ALIAS {
$$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| ALL {
$$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| NETGROUP {
$$ = new_member($1, NETGROUP);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| NTWKADDR {
$$ = new_member($1, NTWKADDR);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| 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 {
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->runasusers != NULL) {
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,
$1->runasusers, entries);
}
if ($1->runasgroups != NULL) {
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,
$1->runasgroups, entries);
}
sudo_efree($1);
free($1);
}
#ifdef HAVE_SELINUX
cs->role = $2.role;
@@ -365,15 +439,31 @@ cmndspec : runasspec selinux solarisprivs cmndtag digcmnd {
digest : SHA224_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA224, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| SHA256_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA256, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| SHA384_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA384, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| SHA512_TOK ':' DIGEST {
$$ = new_digest(SUDO_DIGEST_SHA512, $3);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
;
@@ -473,29 +563,61 @@ runasspec : /* empty */ {
;
runaslist : /* empty */ {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer));
$$ = calloc(1, sizeof(struct runascontainer));
if ($$ != NULL) {
$$->runasusers = new_member(NULL, MYSELF);
/* $$->runasgroups = NULL; */
if ($$->runasusers == NULL) {
free($$);
$$ = NULL;
}
}
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| userlist {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer));
$$ = calloc(1, sizeof(struct runascontainer));
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
$$->runasusers = $1;
/* $$->runasgroups = NULL; */
}
| userlist ':' grouplist {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer));
$$ = calloc(1, sizeof(struct runascontainer));
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
$$->runasusers = $1;
$$->runasgroups = $3;
}
| ':' grouplist {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer));
$$ = calloc(1, sizeof(struct runascontainer));
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
/* $$->runasusers = NULL; */
$$->runasgroups = $2;
}
| ':' {
$$ = sudo_ecalloc(1, sizeof(struct runascontainer));
$$ = calloc(1, sizeof(struct runascontainer));
if ($$ != 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 {
$$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| ALIAS {
$$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| 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->args = $1.args;
$$ = new_member((char *)c, COMMAND);
if ($$ == NULL) {
free(c);
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
;
@@ -640,18 +779,38 @@ opuser : user {
user : ALIAS {
$$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| ALL {
$$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| NETGROUP {
$$ = new_member($1, NETGROUP);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| USERGROUP {
$$ = new_member($1, USERGROUP);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| WORD {
$$ = new_member($1, WORD);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
;
@@ -674,12 +833,24 @@ opgroup : group {
group : ALIAS {
$$ = new_member($1, ALIAS);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| ALL {
$$ = new_member(NULL, ALL);
if ($$ == NULL) {
sudoerserror(N_("unable to allocate memory"));
YYERROR;
}
}
| 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. */
if (errorlineno == -1) {
errorlineno = sudolineno;
errorfile = sudo_estrdup(sudoers);
errorfile = sudoers;
}
if (sudoers_warnings && s != NULL) {
LEXTRACE("<*> ");
@@ -722,13 +893,15 @@ new_default(char *var, char *val, int op)
struct defaults *d;
debug_decl(new_default, SUDOERS_DEBUG_PARSER)
d = sudo_ecalloc(1, sizeof(struct defaults));
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);
}
debug_return_ptr(d);
}
@@ -739,10 +912,12 @@ new_member(char *name, int type)
struct member *m;
debug_decl(new_member, SUDOERS_DEBUG_PARSER)
m = sudo_ecalloc(1, sizeof(struct member));
m = calloc(1, sizeof(struct member));
if (m != NULL) {
m->name = name;
m->type = type;
HLTQ_INIT(m, entries);
}
debug_return_ptr(m);
}
@@ -753,9 +928,15 @@ new_digest(int digest_type, const char *digest_str)
struct sudo_digest *dig;
debug_decl(new_digest, SUDOERS_DEBUG_PARSER)
dig = sudo_emalloc(sizeof(*dig));
dig = malloc(sizeof(*dig));
if (dig != NULL) {
dig->digest_type = digest_type;
dig->digest_str = sudo_estrdup(digest_str);
dig->digest_str = strdup(digest_str);
if (dig->digest_str == NULL) {
free(dig);
dig = NULL;
}
}
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
* runas users the entries apply to (specified by the type).
*/
static void
static bool
add_defaults(int type, struct member *bmem, struct defaults *defs)
{
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.
*/
binding = sudo_emalloc(sizeof(*binding));
if ((binding = malloc(sizeof(*binding))) == NULL)
debug_return_bool(false);
if (bmem != NULL)
HLTQ_TO_TAILQ(binding, bmem, entries);
else
@@ -793,25 +975,26 @@ add_defaults(int type, struct member *bmem, struct defaults *defs)
TAILQ_CONCAT_HLTQ(&defaults, defs, entries);
}
debug_return;
debug_return_bool(true);
}
/*
* Allocate a new struct userspec, populate it, and insert it at the
* end of the userspecs list.
*/
static void
static bool
add_userspec(struct member *members, struct privilege *privs)
{
struct userspec *u;
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->privileges, privs, 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;
TAILQ_FOREACH_SAFE(m, &us->users, entries, m_next) {
sudo_efree(m->name);
sudo_efree(m);
free(m->name);
free(m);
}
TAILQ_FOREACH_SAFE(priv, &us->privileges, entries, priv_next) {
struct member_list *runasuserlist = NULL, *runasgrouplist = NULL;
@@ -846,62 +1029,62 @@ init_parser(const char *path, bool quiet)
#endif /* HAVE_PRIV_SET */
TAILQ_FOREACH_SAFE(m, &priv->hostlist, entries, m_next) {
sudo_efree(m->name);
sudo_efree(m);
free(m->name);
free(m);
}
TAILQ_FOREACH_SAFE(cs, &priv->cmndlist, entries, cs_next) {
#ifdef HAVE_SELINUX
/* Only free the first instance of a role/type. */
if (cs->role != role) {
role = cs->role;
sudo_efree(cs->role);
free(cs->role);
}
if (cs->type != type) {
type = cs->type;
sudo_efree(cs->type);
free(cs->type);
}
#endif /* HAVE_SELINUX */
#ifdef HAVE_PRIV_SET
/* Only free the first instance of privs/limitprivs. */
if (cs->privs != privs) {
privs = cs->privs;
sudo_efree(cs->privs);
free(cs->privs);
}
if (cs->limitprivs != limitprivs) {
limitprivs = cs->limitprivs;
sudo_efree(cs->limitprivs);
free(cs->limitprivs);
}
#endif /* HAVE_PRIV_SET */
/* Only free the first instance of runas user/group lists. */
if (cs->runasuserlist && cs->runasuserlist != runasuserlist) {
runasuserlist = cs->runasuserlist;
TAILQ_FOREACH_SAFE(m, runasuserlist, entries, m_next) {
sudo_efree(m->name);
sudo_efree(m);
free(m->name);
free(m);
}
sudo_efree(runasuserlist);
free(runasuserlist);
}
if (cs->runasgrouplist && cs->runasgrouplist != runasgrouplist) {
runasgrouplist = cs->runasgrouplist;
TAILQ_FOREACH_SAFE(m, runasgrouplist, entries, m_next) {
sudo_efree(m->name);
sudo_efree(m);
free(m->name);
free(m);
}
sudo_efree(runasgrouplist);
free(runasgrouplist);
}
if (cs->cmnd->type == COMMAND) {
struct sudo_command *c =
(struct sudo_command *) cs->cmnd->name;
sudo_efree(c->cmnd);
sudo_efree(c->args);
free(c->cmnd);
free(c->args);
}
sudo_efree(cs->cmnd->name);
sudo_efree(cs->cmnd);
sudo_efree(cs);
free(cs->cmnd->name);
free(cs->cmnd);
free(cs);
}
sudo_efree(priv);
free(priv);
}
sudo_efree(us);
free(us);
}
TAILQ_INIT(&userspecs);
@@ -915,17 +1098,17 @@ init_parser(const char *path, bool quiet)
if (m->type == COMMAND) {
struct sudo_command *c =
(struct sudo_command *) m->name;
sudo_efree(c->cmnd);
sudo_efree(c->args);
free(c->cmnd);
free(c->args);
}
sudo_efree(m->name);
sudo_efree(m);
free(m->name);
free(m);
}
sudo_efree(d->binding);
free(d->binding);
}
sudo_efree(d->var);
sudo_efree(d->val);
sudo_efree(d);
free(d->var);
free(d->val);
free(d);
}
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)
goto bad;
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
sudo_efree(path);
free(path);
continue;
}
pl = malloc(sizeof(*pl));
if (pl == NULL) {
sudo_efree(path);
free(path);
goto bad;
}
pl->path = path;
@@ -4092,8 +4092,8 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
max_paths <<= 1;
tmp = reallocarray(paths, max_paths, sizeof(*paths));
if (tmp == NULL) {
sudo_efree(path);
sudo_efree(pl);
free(path);
free(pl);
goto bad;
}
paths = tmp;
@@ -4102,7 +4102,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
}
closedir(dir);
if (count == 0) {
sudo_efree(paths);
free(paths);
paths = NULL;
}
*pathsp = paths;
@@ -4111,10 +4111,10 @@ bad:
if (dir != NULL)
closedir(dir);
for (i = 0; i < count; i++) {
sudo_efree(paths[i]->path);
sudo_efree(paths[i]);
free(paths[i]->path);
free(paths[i]);
}
sudo_efree(paths);
free(paths);
debug_return_int(-1);
}
@@ -4138,7 +4138,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
for (i = 0; i < count; i++) {
SLIST_INSERT_HEAD(&stack->more, paths[i], entries);
}
sudo_efree(paths);
free(paths);
}
debug_return_int(count);
@@ -4161,15 +4161,15 @@ init_lexer(void)
idepth--;
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
sudo_efree(pl->path);
sudo_efree(pl);
free(pl->path);
free(pl);
}
sudo_efree(istack[idepth].path);
free(istack[idepth].path);
if (idepth && !istack[idepth].keepopen)
fclose(istack[idepth].bs->yy_input_file);
sudoers_delete_buffer(istack[idepth].bs);
}
sudo_efree(istack);
free(istack);
istack = NULL;
istacksize = idepth = 0;
sudolineno = 1;
@@ -4246,20 +4246,20 @@ push_include_int(char *path, bool isdir)
count = switch_dir(&istack[idepth], path);
if (count <= 0) {
/* switch_dir() called sudoerserror() for us */
sudo_efree(path);
free(path);
debug_return_bool(count ? false : true);
}
/* Parse the first dir entry we can open, leave the rest for later. */
do {
sudo_efree(path);
free(path);
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
/* Unable to open any files in include dir, not an error. */
debug_return_bool(true);
}
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
path = pl->path;
sudo_efree(pl);
free(pl);
} while ((fp = open_sudoers(path, false, &keepopen)) == NULL);
} else {
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
@@ -4299,22 +4299,22 @@ pop_include(void)
SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries);
fp = open_sudoers(pl->path, false, &keepopen);
if (fp != NULL) {
sudo_efree(sudoers);
free(sudoers);
sudoers = pl->path;
sudolineno = 1;
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
sudo_efree(pl);
free(pl);
break;
}
/* Unable to open path in include dir, go to next one. */
sudo_efree(pl->path);
sudo_efree(pl);
free(pl->path);
free(pl);
}
/* If no path list, just pop the last dir on the stack. */
if (pl == NULL) {
idepth--;
sudoers_switch_to_buffer(istack[idepth].bs);
sudo_efree(sudoers);
free(sudoers);
sudoers = istack[idepth].path;
sudolineno = istack[idepth].lineno;
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)
goto bad;
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
sudo_efree(path);
free(path);
continue;
}
pl = malloc(sizeof(*pl));
if (pl == NULL) {
sudo_efree(path);
free(path);
goto bad;
}
pl->path = path;
@@ -821,8 +821,8 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
max_paths <<= 1;
tmp = reallocarray(paths, max_paths, sizeof(*paths));
if (tmp == NULL) {
sudo_efree(path);
sudo_efree(pl);
free(path);
free(pl);
goto bad;
}
paths = tmp;
@@ -831,7 +831,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
}
closedir(dir);
if (count == 0) {
sudo_efree(paths);
free(paths);
paths = NULL;
}
*pathsp = paths;
@@ -840,10 +840,10 @@ bad:
if (dir != NULL)
closedir(dir);
for (i = 0; i < count; i++) {
sudo_efree(paths[i]->path);
sudo_efree(paths[i]);
free(paths[i]->path);
free(paths[i]);
}
sudo_efree(paths);
free(paths);
debug_return_int(-1);
}
@@ -867,7 +867,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
for (i = 0; i < count; i++) {
SLIST_INSERT_HEAD(&stack->more, paths[i], entries);
}
sudo_efree(paths);
free(paths);
}
debug_return_int(count);
@@ -890,15 +890,15 @@ init_lexer(void)
idepth--;
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
sudo_efree(pl->path);
sudo_efree(pl);
free(pl->path);
free(pl);
}
sudo_efree(istack[idepth].path);
free(istack[idepth].path);
if (idepth && !istack[idepth].keepopen)
fclose(istack[idepth].bs->yy_input_file);
sudoers_delete_buffer(istack[idepth].bs);
}
sudo_efree(istack);
free(istack);
istack = NULL;
istacksize = idepth = 0;
sudolineno = 1;
@@ -975,20 +975,20 @@ push_include_int(char *path, bool isdir)
count = switch_dir(&istack[idepth], path);
if (count <= 0) {
/* switch_dir() called sudoerserror() for us */
sudo_efree(path);
free(path);
debug_return_bool(count ? false : true);
}
/* Parse the first dir entry we can open, leave the rest for later. */
do {
sudo_efree(path);
free(path);
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
/* Unable to open any files in include dir, not an error. */
debug_return_bool(true);
}
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
path = pl->path;
sudo_efree(pl);
free(pl);
} while ((fp = open_sudoers(path, false, &keepopen)) == NULL);
} else {
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
@@ -1028,22 +1028,22 @@ pop_include(void)
SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries);
fp = open_sudoers(pl->path, false, &keepopen);
if (fp != NULL) {
sudo_efree(sudoers);
free(sudoers);
sudoers = pl->path;
sudolineno = 1;
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
sudo_efree(pl);
free(pl);
break;
}
/* Unable to open path in include dir, go to next one. */
sudo_efree(pl->path);
sudo_efree(pl);
free(pl->path);
free(pl);
}
/* If no path list, just pop the last dir on the stack. */
if (pl == NULL) {
idepth--;
sudoers_switch_to_buffer(istack[idepth].bs);
sudo_efree(sudoers);
free(sudoers);
sudoers = istack[idepth].path;
sudolineno = istack[idepth].lineno;
keepopen = istack[idepth].keepopen;

View File

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