]> jfr.im git - solanum.git/blobdiff - src/ircd_parser.y
Fix a couple more string leaks.
[solanum.git] / src / ircd_parser.y
index 153dcfb1ef4a796d2c4da9d40104d136d1d5eaf1..e8df7653ea12a2e45c6eeb59d7bf8b22664af1ab 100644 (file)
 
 #define YY_NO_UNPUT
 
-int yyparse();
+int yyparse(void);
 int yyerror(const char *);
-int yylex();
+int yylex(void);
 
 static time_t conf_find_time(char*);
 
 static struct {
        const char *    name;
        const char *    plural;
-       time_t  val;
+       time_t  val;
 } ircd_times[] = {
        {"second",     "seconds",    1},
        {"minute",     "minutes",    60},
@@ -44,7 +44,7 @@ static struct {
        {"fortnight",  "fortnights", 60 * 60 * 24 * 14},
        {"month",      "months",     60 * 60 * 24 * 7 * 4},
        {"year",       "years",      60 * 60 * 24 * 365},
-       /* ok-- we now do sizes here too. they aren't times, but 
+       /* ok-- we now do sizes here too. they aren't times, but
           it's close enough */
        {"byte",        "bytes",        1},
        {"kb",          NULL,           1024},
@@ -101,31 +101,31 @@ static int        conf_get_yesno_value(char *str)
 
 static void    free_cur_list(conf_parm_t* list)
 {
-       switch (list->type & CF_MTYPE)
-       {
-               case CF_STRING:
-               case CF_QSTRING:
-                       MyFree(list->v.string);
-                       break;
-               case CF_LIST:
-                       free_cur_list(list->v.list);
-                       break;
-               default: break;
+       if (list->type == CF_STRING || list->type == CF_QSTRING) {
+               rb_free(list->v.string);
+       } else if (list->type == CF_FLIST) {
+               /* Even though CF_FLIST is a flag, comparing with == is valid
+                * because conf_parm_t.type must be either a type or one flag.
+                */
+               free_cur_list(list->v.list);
        }
 
-       if (list->next)
+       if (list->next) {
                free_cur_list(list->next);
+       }
+
+       rb_free(list);
 }
 
-               
+
 conf_parm_t *  cur_list = NULL;
 
 static void    add_cur_list_cpt(conf_parm_t *new)
 {
        if (cur_list == NULL)
        {
-               cur_list = MyMalloc(sizeof(conf_parm_t));
-               cur_list->type |= CF_FLIST;
+               cur_list = rb_malloc(sizeof(conf_parm_t));
+               cur_list->type = CF_FLIST;
                cur_list->v.list = new;
        }
        else
@@ -139,7 +139,7 @@ static void add_cur_list(int type, char *str, int number)
 {
        conf_parm_t *new;
 
-       new = MyMalloc(sizeof(conf_parm_t));
+       new = rb_malloc(sizeof(conf_parm_t));
        new->next = NULL;
        new->type = type;
 
@@ -152,7 +152,7 @@ static void add_cur_list(int type, char *str, int number)
                break;
        case CF_STRING:
        case CF_QSTRING:
-               DupString(new->v.string, str);
+               new->v.string = rb_strdup(str);
                break;
        }
 
@@ -163,8 +163,8 @@ static void add_cur_list(int type, char *str, int number)
 %}
 
 %union {
-       int             number;
-       char            string[IRCD_BUFSIZE + 1];
+       int             number;
+       char            string[IRCD_BUFSIZE + 1];
        conf_parm_t *   conf_parm;
 }
 
@@ -174,15 +174,15 @@ static void       add_cur_list(int type, char *str, int number)
 %token <number> NUMBER
 
 %type <string> qstring string
-%type <number> number timespec 
+%type <number> number timespec
 %type <conf_parm> oneitem single itemlist
 
 %start conf
 
 %%
 
-conf: 
-       | conf conf_item 
+conf:
+       | conf conf_item
        | error
        ;
 
@@ -190,33 +190,33 @@ conf_item: block
         | loadmodule
          ;
 
-block: string 
-         { 
+block: string
+         {
            conf_start_block($1, NULL);
          }
-       '{' block_items '}' ';' 
+       '{' block_items '}' ';'
          {
           if (conf_cur_block)
-               conf_end_block(conf_cur_block);
+                  conf_end_block(conf_cur_block);
          }
-     | string qstring 
-         { 
+     | string qstring
+         {
            conf_start_block($1, $2);
          }
        '{' block_items '}' ';'
          {
           if (conf_cur_block)
-               conf_end_block(conf_cur_block);
+                  conf_end_block(conf_cur_block);
          }
      ;
 
-block_items: block_items block_item 
-           | block_item 
+block_items: block_items block_item
+           | block_item
            ;
 
 block_item:    string '=' itemlist ';'
                {
-                       conf_call_set(conf_cur_block, $1, cur_list, CF_LIST);
+                       conf_call_set(conf_cur_block, $1, cur_list);
                        free_cur_list(cur_list);
                        cur_list = NULL;
                }
@@ -233,8 +233,7 @@ single: oneitem
        | oneitem TWODOTS oneitem
        {
                /* "1 .. 5" meaning 1,2,3,4,5 - only valid for integers */
-               if (($1->type & CF_MTYPE) != CF_INT ||
-                   ($3->type & CF_MTYPE) != CF_INT)
+               if ($1->type != CF_INT || $3->type != CF_INT)
                {
                        conf_report_error("Both arguments in '..' notation must be integers.");
                        break;
@@ -253,29 +252,29 @@ single: oneitem
 
 oneitem: qstring
             {
-               $$ = MyMalloc(sizeof(conf_parm_t));
+               $$ = rb_malloc(sizeof(conf_parm_t));
                $$->type = CF_QSTRING;
-               DupString($$->v.string, $1);
+               $$->v.string = rb_strdup($1);
            }
           | timespec
             {
-               $$ = MyMalloc(sizeof(conf_parm_t));
+               $$ = rb_malloc(sizeof(conf_parm_t));
                $$->type = CF_TIME;
                $$->v.number = $1;
            }
           | number
             {
-               $$ = MyMalloc(sizeof(conf_parm_t));
+               $$ = rb_malloc(sizeof(conf_parm_t));
                $$->type = CF_INT;
                $$->v.number = $1;
            }
           | string
             {
-               /* a 'string' could also be a yes/no value .. 
+               /* a 'string' could also be a yes/no value ..
                   so pass it as that, if so */
                int val = conf_get_yesno_value($1);
 
-               $$ = MyMalloc(sizeof(conf_parm_t));
+               $$ = rb_malloc(sizeof(conf_parm_t));
 
                if (val != -1)
                {
@@ -285,7 +284,7 @@ oneitem: qstring
                else
                {
                        $$->type = CF_STRING;
-                       DupString($$->v.string, $1);
+                       $$->v.string = rb_strdup($1);
                }
             }
           ;
@@ -296,10 +295,12 @@ loadmodule:
 #ifndef STATIC_MODULES
               char *m_bn;
 
-              m_bn = irc_basename((char *) $2);
+              m_bn = rb_basename((char *) $2);
 
               if (findmodule_byname(m_bn) == -1)
                  load_one_module($2, 0);
+
+              rb_free(m_bn);
 #endif
            }
          ';'
@@ -310,7 +311,7 @@ string: STRING { strcpy($$, $1); } ;
 number: NUMBER { $$ = $1; } ;
 
 timespec:      number string
-               {
+               {
                        time_t t;
 
                        if ((t = conf_find_time($2)) == 0)
@@ -318,7 +319,7 @@ timespec:   number string
                                conf_report_error("Unrecognised time type/size '%s'", $2);
                                t = 1;
                        }
-           
+
                        $$ = $1 * t;
                }
                | timespec timespec