From: Pierangelo Masarati Date: Thu, 2 May 2002 08:48:14 +0000 (+0000) Subject: Fixes ITS#1786: dynamically growing number of tokens in config line X-Git-Tag: OPENLDAP_REL_ENG_2_MP~117 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2ca323d2b52d259feab620e984ad1150cca796f3;p=openldap Fixes ITS#1786: dynamically growing number of tokens in config line for both slapd and slurpd Copyright 2002, John Morrissey (jwm at horde dot net), All rights reserved. This is free software; you can redistribute and use it under the same terms as OpenLDAP itself. Applied with changes --- diff --git a/servers/slapd/config.c b/servers/slapd/config.c index b4197a0807..23a4599f06 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -18,7 +18,7 @@ #include "ldap_pvt.h" #include "slap.h" -#define MAXARGS 500 +#define ARGS_STEP 512 /* * defaults for various global variables @@ -45,6 +45,8 @@ char *global_host = NULL; char *global_realm = NULL; char *ldap_srvtab = ""; char *default_passwd_hash = NULL; +int cargc = 0, cargv_size = 0; +char **cargv; struct berval default_search_base = { 0, NULL }; struct berval default_search_nbase = { 0, NULL }; unsigned num_subordinates = 0; @@ -68,7 +70,7 @@ int use_reverse_lookup = 0; static char *fp_getline(FILE *fp, int *lineno); static void fp_getline_init(int *lineno); -static int fp_parse_line(int lineno, char *line, int *argcp, char **argv); +static int fp_parse_line(int lineno, char *line); static char *strtok_quote(char *line, char *sep); static int load_ucdata(char *path); @@ -78,8 +80,7 @@ read_config( const char *fname ) { FILE *fp; char *line, *savefname, *saveline; - int cargc, savelineno; - char *cargv[MAXARGS+1]; + int savelineno; int lineno, i; int rc; struct berval vals[2]; @@ -90,6 +91,9 @@ read_config( const char *fname ) vals[1].bv_val = NULL; + cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) ); + cargv_size = ARGS_STEP + 1; + if ( (fp = fopen( fname, "r" )) == NULL ) { ldap_syslog = 1; #ifdef NEW_LOGGING @@ -123,7 +127,7 @@ read_config( const char *fname ) /* fp_parse_line is destructive, we save a copy */ saveline = ch_strdup( line ); - if ( fp_parse_line( lineno, line, &cargc, cargv ) != 0 ) { + if ( fp_parse_line( lineno, line ) != 0 ) { return( 1 ); } @@ -2345,16 +2349,14 @@ read_config( const char *fname ) static int fp_parse_line( int lineno, - char *line, - int *argcp, - char **argv + char *line ) { char * token; char * logline; char logbuf[sizeof("pseudorootpw ***")]; - *argcp = 0; + cargc = 0; token = strtok_quote( line, " \t" ); logline = line; @@ -2377,21 +2379,28 @@ fp_parse_line( *strtok_quote_ptr = '\0'; for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) { - if ( *argcp == MAXARGS ) { + if ( cargc == cargv_size - 1 ) { + char **tmp; + tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) * + sizeof(*cargv) ); + if ( tmp == NULL ) { #ifdef NEW_LOGGING - LDAP_LOG(( "config", LDAP_LEVEL_CRIT, - "fp_parse_line: too many tokens (%d max).\n", - MAXARGS )); + LDAP_LOG(( "config", LDAP_LEVEL_ERR, + "line %d: out of memory\n", + lineno )); #else - Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n", - MAXARGS, 0, 0 ); + Debug( LDAP_DEBUG_ANY, + "line %d: out of memory\n", + lineno, 0, 0 ); #endif - - return( 1 ); + return -1; + } + cargv = tmp; + cargv_size += ARGS_STEP; } - argv[(*argcp)++] = token; + cargv[cargc++] = token; } - argv[*argcp] = NULL; + cargv[cargc] = NULL; return 0; } diff --git a/servers/slurpd/config.c b/servers/slurpd/config.c index db08952915..bd47c26a61 100644 --- a/servers/slurpd/config.c +++ b/servers/slurpd/config.c @@ -34,15 +34,17 @@ #include "slurp.h" #include "globals.h" -#define MAXARGS 500 +#define ARGS_STEP 512 /* Forward declarations */ static void add_replica LDAP_P(( char **, int )); static int parse_replica_line LDAP_P(( char **, int, Ri *)); -static void parse_line LDAP_P(( char *, int *, char ** )); +static void parse_line LDAP_P(( char * )); static char *getline LDAP_P(( FILE * )); static char *strtok_quote LDAP_P(( char *, char * )); +int cargc = 0, cargv_size = 0; +char **cargv; /* current config file line # */ static int lineno; @@ -60,8 +62,9 @@ slurpd_read_config( { FILE *fp; char *line; - int cargc; - char *cargv[MAXARGS]; + + cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) ); + cargv_size = ARGS_STEP + 1; #ifdef NEW_LOGGING LDAP_LOG (( "config", LDAP_LEVEL_ARGS, @@ -90,7 +93,7 @@ slurpd_read_config( Debug( LDAP_DEBUG_CONFIG, "Config: (%s)\n", line, 0, 0 ); #endif - parse_line( line, &cargc, cargv ); + parse_line( line ); if ( cargc < 1 ) { fprintf( stderr, "line %d: bad config line (ignored)\n", lineno ); @@ -172,19 +175,30 @@ slurpd_read_config( */ static void parse_line( - char *line, - int *argcp, - char **argv + char *line ) { char * token; - *argcp = 0; + cargc = 0; for ( token = strtok_quote( line, " \t" ); token != NULL; - token = strtok_quote( NULL, " \t" ) ) { - argv[(*argcp)++] = token; + token = strtok_quote( NULL, " \t" ) ) + { + if ( cargc == cargv_size - 1 ) { + char **tmp; + tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) * + sizeof(*cargv) ); + if (tmp == NULL) { + cargc = 0; + return; + } + cargv = tmp; + cargv_size += ARGS_STEP; + } + + cargv[cargc++] = token; } - argv[*argcp] = NULL; + cargv[cargc] = NULL; }