removing the limit on the maximum number of items in the black_function_list
authorMuhammad Usama <m.usama@gmail.com>
Thu, 7 Apr 2016 18:37:22 +0000 (23:37 +0500)
committerMuhammad Usama <m.usama@gmail.com>
Thu, 7 Apr 2016 18:37:22 +0000 (23:37 +0500)
and white_function_list lists.

extract_string_tokens in pool_config uses the fixed size malloc on the array to
hold the black_function_list/white_function_list items. This imposes a limit of
maximum items in these lists. The fix is to use realloc to increase the array
size when it gets full.

pool_config.c
pool_config.l

index fc830cceef4e64ab2458dcd7745294ec70852124..773a10b4ae881c60d64f430b7b7cd016d3c35322 100644 (file)
@@ -46,6 +46,7 @@ typedef int16_t flex_int16_t;
 typedef uint16_t flex_uint16_t;
 typedef int32_t flex_int32_t;
 typedef uint32_t flex_uint32_t;
+typedef uint64_t flex_uint64_t;
 #else
 typedef signed char flex_int8_t;
 typedef short int flex_int16_t;
@@ -53,6 +54,7 @@ typedef int flex_int32_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -83,8 +85,6 @@ typedef unsigned int flex_uint32_t;
 #define UINT32_MAX             (4294967295U)
 #endif
 
-#endif /* ! C99 */
-
 #endif /* ! FLEXINT_H */
 
 #ifdef __cplusplus
@@ -141,15 +141,7 @@ typedef unsigned int flex_uint32_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
 #define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
 #endif
 
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -161,7 +153,12 @@ typedef unsigned int flex_uint32_t;
 typedef struct yy_buffer_state *YY_BUFFER_STATE;
 #endif
 
-extern int yyleng;
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+extern yy_size_t yyleng;
 
 extern FILE *yyin, *yyout;
 
@@ -187,11 +184,6 @@ extern FILE *yyin, *yyout;
 
 #define unput(c) yyunput( c, (yytext_ptr)  )
 
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
 #ifndef YY_STRUCT_YY_BUFFER_STATE
 #define YY_STRUCT_YY_BUFFER_STATE
 struct yy_buffer_state
@@ -209,7 +201,7 @@ struct yy_buffer_state
        /* Number of characters read into yy_ch_buf, not including EOB
         * characters.
         */
-       int yy_n_chars;
+       yy_size_t yy_n_chars;
 
        /* Whether we "own" the buffer - i.e., we know we created it,
         * and can realloc() it to grow it, and should free() it to
@@ -279,8 +271,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
 
 /* yy_hold_char holds the character lost when yytext is formed. */
 static char yy_hold_char;
-static int yy_n_chars;         /* number of characters read into yy_ch_buf */
-int yyleng;
+static yy_size_t yy_n_chars;           /* number of characters read into yy_ch_buf */
+yy_size_t yyleng;
 
 /* Points to current character in buffer. */
 static char *yy_c_buf_p = (char *) 0;
@@ -308,7 +300,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file  );
 
 YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size  );
 YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str  );
-YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len  );
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len  );
 
 void *yyalloc (yy_size_t  );
 void *yyrealloc (void *,yy_size_t  );
@@ -366,7 +358,7 @@ static void yy_fatal_error (yyconst char msg[]  );
  */
 #define YY_DO_BEFORE_ACTION \
        (yytext_ptr) = yy_bp; \
-       yyleng = (size_t) (yy_cp - yy_bp); \
+       yyleng = (yy_size_t) (yy_cp - yy_bp); \
        (yy_hold_char) = *yy_cp; \
        *yy_cp = '\0'; \
        (yy_c_buf_p) = yy_cp;
@@ -550,7 +542,7 @@ static char *extract_string(char *value, POOL_TOKEN token);
 static char **extract_string_tokens(char *str, char *delim, int *n);
 static void clear_host_entry(int slot);
 
-#line 554 "pool_config.c"
+#line 546 "pool_config.c"
 
 #define INITIAL 0
 
@@ -589,7 +581,7 @@ FILE *yyget_out (void );
 
 void yyset_out  (FILE * out_str  );
 
-int yyget_leng (void );
+yy_size_t yyget_leng (void );
 
 char *yyget_text (void );
 
@@ -629,12 +621,7 @@ static int input (void );
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
 #define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
 #endif
 
 /* Copy whatever the last rule matched to the standard output. */
@@ -642,7 +629,7 @@ static int input (void );
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#define ECHO fwrite( yytext, yyleng, 1, yyout )
 #endif
 
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -653,7 +640,7 @@ static int input (void );
        if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
                { \
                int c = '*'; \
-               size_t n; \
+               yy_size_t n; \
                for ( n = 0; n < max_size && \
                             (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
                        buf[n] = (char) c; \
@@ -738,7 +725,7 @@ YY_DECL
 #line 85 "pool_config.l"
 
 
-#line 742 "pool_config.c"
+#line 729 "pool_config.c"
 
        if ( !(yy_init) )
                {
@@ -876,7 +863,7 @@ YY_RULE_SETUP
 #line 100 "pool_config.l"
 ECHO;
        YY_BREAK
-#line 880 "pool_config.c"
+#line 867 "pool_config.c"
 case YY_STATE_EOF(INITIAL):
        yyterminate();
 
@@ -1063,7 +1050,7 @@ static int yy_get_next_buffer (void)
 
        else
                {
-                       int num_to_read =
+                       yy_size_t num_to_read =
                        YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
 
                while ( num_to_read <= 0 )
@@ -1077,7 +1064,7 @@ static int yy_get_next_buffer (void)
 
                        if ( b->yy_is_our_buffer )
                                {
-                               int new_size = b->yy_buf_size * 2;
+                               yy_size_t new_size = b->yy_buf_size * 2;
 
                                if ( new_size <= 0 )
                                        b->yy_buf_size += b->yy_buf_size / 8;
@@ -1108,7 +1095,7 @@ static int yy_get_next_buffer (void)
 
                /* Read in more data. */
                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-                       (yy_n_chars), (size_t) num_to_read );
+                       (yy_n_chars), num_to_read );
 
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
                }
@@ -1230,7 +1217,7 @@ static int yy_get_next_buffer (void)
 
                else
                        { /* need more input */
-                       int offset = (yy_c_buf_p) - (yytext_ptr);
+                       yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
                        ++(yy_c_buf_p);
 
                        switch ( yy_get_next_buffer(  ) )
@@ -1254,7 +1241,7 @@ static int yy_get_next_buffer (void)
                                case EOB_ACT_END_OF_FILE:
                                        {
                                        if ( yywrap( ) )
-                                               return EOF;
+                                               return 0;
 
                                        if ( ! (yy_did_buffer_switch_on_eof) )
                                                YY_NEW_FILE;
@@ -1502,7 +1489,7 @@ void yypop_buffer_state (void)
  */
 static void yyensure_buffer_stack (void)
 {
-       int num_to_alloc;
+       yy_size_t num_to_alloc;
     
        if (!(yy_buffer_stack)) {
 
@@ -1594,17 +1581,16 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
 
 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
  * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
  * 
  * @return the newly allocated buffer state object.
  */
-YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, int  _yybytes_len )
+YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len )
 {
        YY_BUFFER_STATE b;
        char *buf;
-       yy_size_t n;
-       int i;
+       yy_size_t n, i;
     
        /* Get memory for full buffer, including space for trailing EOB's. */
        n = _yybytes_len + 2;
@@ -1686,7 +1672,7 @@ FILE *yyget_out  (void)
 /** Get the length of the current token.
  * 
  */
-int yyget_leng  (void)
+yy_size_t yyget_leng  (void)
 {
         return yyleng;
 }
@@ -3902,11 +3888,11 @@ int eval_logical(char *str)
  * array of pointers to malloced strings. number of tokens is set to
  * n; note that str will be destroyed by strtok().
  */
-#define MAXTOKENS 1024
+#define MAXTOKENS 256
 static char **extract_string_tokens(char *str, char *delimi, int *n)
 {
        char *token;
-       static char **tokens;
+       char **tokens;
 
        *n = 0;
 
@@ -3917,7 +3903,7 @@ static char **extract_string_tokens(char *str, char *delimi, int *n)
                return NULL;
        }
 
-       for (token = strtok(str, delimi); token != NULL && *n < MAXTOKENS; token = strtok(NULL, delimi))
+       for (token = strtok(str, delimi); token != NULL; token = strtok(NULL, delimi))
        {
                tokens[*n] = strdup(token);
                if (tokens[*n] == NULL)
@@ -3927,6 +3913,16 @@ static char **extract_string_tokens(char *str, char *delimi, int *n)
                }
                pool_debug("extract_string_tokens: token: %s", tokens[*n]);
                (*n)++;
+
+               if ( ((*n) % MAXTOKENS ) == 0)
+               {
+                       tokens = realloc(tokens, (MAXTOKENS * sizeof(char *) * (((*n)/MAXTOKENS) +1) ));
+                       if (tokens == NULL)
+                       {
+                               pool_error("extract_string_tokens: out of memory");
+                               return NULL;
+                       }
+               }
        }
        return tokens;
 }
index a81d27572a96b4a84da55747dc5902c4e367437a..80d05a34455acceeb8ca48376d95eae33699189b 100644 (file)
@@ -2163,11 +2163,11 @@ int eval_logical(char *str)
  * array of pointers to malloced strings. number of tokens is set to
  * n; note that str will be destroyed by strtok().
  */
-#define MAXTOKENS 1024
+#define MAXTOKENS 256
 static char **extract_string_tokens(char *str, char *delimi, int *n)
 {
        char *token;
-       static char **tokens;
+       char **tokens;
 
        *n = 0;
 
@@ -2178,7 +2178,7 @@ static char **extract_string_tokens(char *str, char *delimi, int *n)
                return NULL;
        }
 
-       for (token = strtok(str, delimi); token != NULL && *n < MAXTOKENS; token = strtok(NULL, delimi))
+       for (token = strtok(str, delimi); token != NULL; token = strtok(NULL, delimi))
        {
                tokens[*n] = strdup(token);
                if (tokens[*n] == NULL)
@@ -2188,6 +2188,16 @@ static char **extract_string_tokens(char *str, char *delimi, int *n)
                }
                pool_debug("extract_string_tokens: token: %s", tokens[*n]);
                (*n)++;
+
+               if ( ((*n) % MAXTOKENS ) == 0)
+               {
+                       tokens = realloc(tokens, (MAXTOKENS * sizeof(char *) * (((*n)/MAXTOKENS) +1) ));
+                       if (tokens == NULL)
+                       {
+                               pool_error("extract_string_tokens: out of memory");
+                               return NULL;
+                       }
+               }
        }
        return tokens;
 }