diff --git a/config.l b/config.l index 8555dae..95bb713 100644 --- a/config.l +++ b/config.l @@ -15,7 +15,8 @@ unsigned int line = 1, col = 0; %} -NUMBER -?[0-9]+ +NEGNUMBER -[0-9]+ +NUMBER [^-][0-9]+ VALUE \".*\" MALSTRING \"[^\"\n]*\n WHITE [\t ]* @@ -23,27 +24,14 @@ COMMENT ^#.* %% -{NUMBER} { - unsigned int x; - errno = 0; - - if (atoi(yytext) < 0) - { - fprintf(stderr,"%s:%d: negative value not accepted! Fix it now!\n", +{NEGNUMBER} { + fprintf(stderr,"%s:%d: negative value not accepted! Fix it now!\n", config, line); - graceful_exit(1); - } - - x = strtoul(yytext, NULL, 10); - - if (errno == ERANGE) - { - fprintf(stderr, "%s:%d: %s is too big! Fix it now!\n", - config, line, yytext); - graceful_exit(1); - } - - yylval.i = x; + graceful_exit(1); +} + +{NUMBER} { + yylval.i = strtoul(yytext, NULL, 10); return TYPE_NUMBER; } @@ -54,8 +42,10 @@ COMMENT ^#.* } {MALSTRING} { + yytext[yyleng - 1] = '\0'; /* remove trailing newline */ /* yytext already contains a newline, no need for one here */ fprintf(stderr, "%s:%d:%d: unterminated string constant: %s\n", config, line, col - yyleng + 1, yytext); + return TYPE_MALSTRING; } {WHITE} { } @@ -80,7 +70,7 @@ COMMENT ^#.* \n { line++; col = 0; } . { - fprintf(stderr, "%s: unrecognized token \"%s\" at line %d, column %d\n", config, yytext, line, col); + fprintf(stderr, "%s:%d:%d unrecognized token \"%s\"\n", config, line, col, yytext); } %% diff --git a/config.y b/config.y index fd31bd3..02863cd 100644 --- a/config.y +++ b/config.y @@ -26,7 +26,7 @@ static const char* lookup_token (int t); %token TYPE_SUSER TYPE_SGROUP TYPE_SGID TYPE_SUID TYPE_MAX %token TYPE_PATH_NETHACK TYPE_PATH_DGLDIR TYPE_PATH_SPOOL %token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT -%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE +%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_MALSTRING %token TYPE_VALUE %token TYPE_NUMBER %type KeyType @@ -154,6 +154,7 @@ KeyPair: KeyType '=' TYPE_VALUE { free($3); } + | KeyType '=' TYPE_MALSTRING {} | KeyType '=' TYPE_NUMBER { if (!myconfig) { @@ -238,5 +239,5 @@ const char* lookup_token (int t) void yyerror(char const* s) { if (!silent) - fprintf(stderr, "%s: couldn't parse \"%s\" at line %d, column %d: %s\n", config, yytext, line, col, s); + fprintf(stderr, "%s:%d:%d: couldn't parse \"%s\": %s\n", config, line, col, yytext, s); }