now do bounds checking in fill() and append()

This commit is contained in:
Todd C. Miller
1995-09-01 04:24:52 +00:00
parent 57e17e71d1
commit 023afc59e3

View File

@@ -30,9 +30,13 @@ static char rcsid[] = "$Id$";
#endif /* lint */ #endif /* lint */
#include "config.h" #include "config.h"
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif /* HAVE_UNISTD_H */ #endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
@@ -46,6 +50,7 @@ static char rcsid[] = "$Id$";
extern YYSTYPE yylval; extern YYSTYPE yylval;
extern int clearaliases; extern int clearaliases;
int sudolineno = 1; int sudolineno = 1;
static int string_len = 0;
static void fill __P((void)); static void fill __P((void));
static void append __P((void)); static void append __P((void));
@@ -165,7 +170,7 @@ N [0-9][0-9]?[0-9]?
return USERALIAS; return USERALIAS;
} }
l = strlen(yytext) - 1; l = yyleng - 1;
if (isalpha(yytext[l]) || isdigit(yytext[l])) { if (isalpha(yytext[l]) || isdigit(yytext[l])) {
/* NAME is what RFC1034 calls a label */ /* NAME is what RFC1034 calls a label */
LEXTRACE("NAME "); LEXTRACE("NAME ");
@@ -179,12 +184,29 @@ N [0-9][0-9]?[0-9]?
%% %%
static void fill() { static void fill() {
(void) strcpy(yylval.string, yytext);
if (yyleng > MAXCOMMANDLENGTH) {
yyerror("command too long, recompile with a larger MAXCOMMANDLENGTH");
} else {
(void) strcpy(yylval.string, yytext);
string_len = yyleng;
}
} }
static void append() { static void append() {
(void) strcat(yylval.string, " "); char *s;
(void) strcat(yylval.string, yytext);
/*
* Make sure we have enough space...
*/
s = yylval.string + string_len;
string_len += yyleng + 1;
if (string_len > MAXCOMMANDLENGTH) {
yyerror("command too long, recompile with a larger MAXCOMMANDLENGTH");
} else {
*s++ = ' ';
(void) strcpy(s, yytext);
}
} }
int yywrap() int yywrap()