Imported Upstream version 1.8.5
[debian/sudo] / plugins / sudoers / gram.c
index e8fe89761b38f2df2b7442f1f6604b48257f98a0..49c45c97f54a207a412cac87537ddf7e43794c6a 100644 (file)
@@ -12,7 +12,7 @@
 #define YYPREFIX "yy"
 #line 2 "gram.y"
 /*
- * Copyright (c) 1996, 1998-2005, 2007-2011
+ * Copyright (c) 1996, 1998-2005, 2007-2012
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -85,7 +85,7 @@
 extern int sudolineno;
 extern int last_token;
 extern char *sudoers;
-static bool verbose = false;
+bool sudoers_warnings = true;
 bool parse_error = false;
 int errorlineno = -1;
 char *errorfile = NULL;
@@ -118,7 +118,7 @@ yyerror(const char *s)
     }
     if (trace_print != NULL) {
        LEXTRACE("<*> ");
-    } else if (verbose && s != NULL) {
+    } else if (sudoers_warnings && s != NULL) {
        warningx(_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno);
     }
     parse_error = true;
@@ -645,14 +645,14 @@ new_default(char *var, char *val, int op)
     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);
 }
@@ -663,11 +663,11 @@ new_member(char *name, int type)
     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);
 }
@@ -712,11 +712,11 @@ add_userspec(struct member *members, struct privilege *privs)
     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;
@@ -823,7 +823,7 @@ init_parser(const char *path, int quiet)
     parse_error = false;
     errorlineno = -1;
     errorfile = sudoers;
-    verbose = !quiet;
+    sudoers_warnings = !quiet;
 
     debug_return;
 }
@@ -851,7 +851,7 @@ static int yygrowstack()
 #else
 #define YY_SIZE_MAX 0x7fffffff
 #endif
-    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
+    if (!newsize || YY_SIZE_MAX / newsize < sizeof *newss)
         goto bail;
     newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
       (short *)malloc(newsize * sizeof *newss); /* overflow check above */
@@ -859,7 +859,7 @@ static int yygrowstack()
         goto bail;
     yyss = newss;
     yyssp = newss + i;
-    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
+    if (!newsize || YY_SIZE_MAX / newsize < sizeof *newvs)
         goto bail;
     newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
       (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
@@ -1155,11 +1155,11 @@ break;
 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;
@@ -1243,7 +1243,7 @@ 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);
@@ -1343,15 +1343,15 @@ break;
 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;
                        }
@@ -1359,8 +1359,8 @@ break;
 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;
@@ -1446,7 +1446,7 @@ 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);