Skip to content

Commit

Permalink
Fix buffer overflow problem when reporting a syntax error with a very…
Browse files Browse the repository at this point in the history
… long

input line
  • Loading branch information
emdenrg committed Oct 4, 2013
1 parent d55bb74 commit 7aaddf5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/cgraph/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
%{
#include <grammar.h>
#include <cghdr.h>
#include <agxbuf.h>
#include <ctype.h>
#define GRAPH_EOF_TOKEN '@' /* lex class must be defined below */
/* this is a workaround for linux flex */
Expand Down Expand Up @@ -191,13 +192,21 @@ ID ({NAME}|{NUMBER})
%%
void yyerror(char *str)
{
unsigned char xbuf[BUFSIZ];
char buf[BUFSIZ];
if (InputFile)
sprintf(buf,"%s:%d: %s in line %d near '%s'\n",InputFile, line_num,
str,line_num,yytext);
else
sprintf(buf," %s in line %d near '%s'\n", str,line_num,yytext);
agerr(AGWARN,buf);
agxbuf xb;
agxbinit(&xb, BUFSIZ, xbuf);
if (InputFile) {
agxbput (&xb, InputFile);
agxbput (&xb, ": ");
}
sprintf(buf," %s in line %d near '", str,line_num);
agxbput (&xb, buf);
agxbput (&xb, yytext);
agxbput (&xb,"'\n");
agerr(AGWARN,agxbuse(&xb));
agxbfree(&xb);
}
/* must be here to see flex's macro defns */
void aglexeof() { unput(GRAPH_EOF_TOKEN); }
Expand Down

0 comments on commit 7aaddf5

Please sign in to comment.