Skip to content

Commit

Permalink
Fix possible buffer overflow problem in chkNum of scanner.
Browse files Browse the repository at this point in the history
  • Loading branch information
emdenrg committed Jan 8, 2014
1 parent 780d605 commit 1d1bdec
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions lib/cgraph/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,32 @@ static void ppDirective (void)
* and report this to the user.
*/
static int chkNum(void) {
unsigned char c = (unsigned char)yytext[yyleng-1]; /* last character */
if (!isdigit(c) && (c != '.')) { /* c is letter */
char buf[BUFSIZ];
sprintf(buf,"syntax error - badly formed number '%s' in line %d of %s\n",yytext,line_num, InputFile);
strcat (buf, "splits into two name tokens\n");
agerr(AGWARN,buf);
return 1;
}
else return 0;
unsigned char c = (unsigned char)yytext[yyleng-1]; /* last character */
if (!isdigit(c) && (c != '.')) { /* c is letter */
unsigned char xbuf[BUFSIZ];
char buf[BUFSIZ];
agxbuf xb;
char* fname;

if (InputFile)
fname = InputFile;
else
fname = "input";

agxbinit(&xb, BUFSIZ, xbuf);

agxbput(&xb,"syntax ambiguity - badly delimited number '");
agxbput(&xb,yytext);
sprintf(buf,"' in line %d of ", line_num);
agxbput(&xb,buf);
agxbput(&xb,fname);
agxbput(&xb, " splits into two tokens\n");
agerr(AGWARN,agxbuse(&xb));

agxbfree(&xb);
return 1;
}
else return 0;
}

/* The LETTER class below consists of ascii letters, underscore, all non-ascii
Expand Down

0 comments on commit 1d1bdec

Please sign in to comment.