Fixed config file parsing to prevent false-positive command matches in some edge cases

This commit is contained in:
Morgan Aldridge 2021-09-09 10:57:44 -04:00
parent 692432b807
commit f6b4a84199
2 changed files with 16 additions and 8 deletions

View File

@ -763,8 +763,9 @@ config_func main_config[]={
void ReadConfigFile( char *configfile ) void ReadConfigFile( char *configfile )
{ {
FILE *fp; FILE *fp;
char str[1024], *file, *cmp; char str[1024], cmp[1024], *file, *str_start, *cmp_end;
int lp; int lp;
size_t len;
#ifdef MLVWMLIBDIR #ifdef MLVWMLIBDIR
char *sysrc; char *sysrc;
size_t sysrc_size; size_t sysrc_size;
@ -796,14 +797,21 @@ void ReadConfigFile( char *configfile )
while( fgetline( str, sizeof(str), fp )!=NULL ){ while( fgetline( str, sizeof(str), fp )!=NULL ){
if( Scr.flags & DEBUGOUT ) if( Scr.flags & DEBUGOUT )
DrawStringMenuBar( str ); DrawStringMenuBar( str );
cmp = str;
if( *cmp == '#' ) continue; str_start = str;
cmp = SkipSpace( cmp ); if( *str_start == '#' ) continue;
if( *cmp == '\n' ) continue; str_start = SkipSpace( str_start );
if( *str_start == '\n' ) continue;
snprintf( cmp, sizeof(cmp), "%s", str_start );
cmp_end = SkipNonSpace( cmp );
*cmp_end = '\0';
for( lp=0; main_config[lp].label!=NULL; lp++ ){ for( lp=0; main_config[lp].label!=NULL; lp++ ){
if( !strncmp( cmp, main_config[lp].label, len = strlen(cmp);
strlen(main_config[lp].label) )){ if( strlen(main_config[lp].label) > len )
len = strlen(main_config[lp].label);
if( !strncmp( cmp, main_config[lp].label, len )){
main_config[lp].action( str, fp ); main_config[lp].action( str, fp );
break; break;
} }

View File

@ -76,7 +76,7 @@ char *LookUpFiles( char *path, char *filename, int mode )
char *SkipNonSpace( char *str ) char *SkipNonSpace( char *str )
{ {
for( ; *str!=' ' && *str!='\t' && *str; str++ ); for( ; *str!=' ' && *str!='\t' && *str!='\n' && *str; str++ );
return str; return str;
} }