diff options
author | Anders Broman <anders.broman@ericsson.com> | 2012-07-09 02:24:07 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2012-07-09 02:24:07 +0000 |
commit | 80aba5ebf74f527c5576179ea1d232b72b8bac35 (patch) | |
tree | bd18bda154d2ed4bc0fc090c6b980de0de3bfbf6 /tools | |
parent | e0d9282f867c9593a4584b09071b310128212426 (diff) |
From Martin Kaiser:
CID 280531: "Argument cannot be negative" in lemon
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7453
svn path=/trunk/; revision=43619
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lemon/lemon.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 606eadc148..d22fe5c8dd 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -2570,8 +2570,11 @@ void Parse(struct lemon *gp) gp->errorcnt++; return; } - fseek(fp,0,2); - filesize = ftell(fp); + if ( fseek(fp,0,SEEK_END)!=0 || (filesize = ftell(fp))<0 ) { + ErrorMsg(ps.filename,0,"Can't determine the file size."); + gp->errorcnt++; + return; + } rewind(fp); /* XXX - what if filesize is bigger than the maximum size_t value? */ filebuf = (char *)malloc( filesize+1 ); @@ -2582,7 +2585,7 @@ void Parse(struct lemon *gp) gp->errorcnt++; return; } - if( fread(filebuf,1,filesize,fp)!=(size_t)filesize ){ + if( fread(filebuf,1,(size_t)filesize,fp)!=(size_t)filesize ){ ErrorMsg(ps.filename,0,"Can't read in all %ld bytes of this file.", filesize); free(filebuf); |