diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-10-24 19:01:39 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-10-25 02:02:16 +0000 |
commit | ad52d7d83aa882ae8f8d6443bc24ef735c5171d4 (patch) | |
tree | e2c4b91f3849df58d255f82356af1817816cddd7 /tools | |
parent | 5c97a4802fdec9013eaf8df8628cbd987bf33978 (diff) |
Bail out immediately if we can't allocate a buffer for carving up $PATH.
Quit immediately, don't even bother allocating a buffer for the pathname
of the file we found.
Revert some other cosmetic changes, to reduce the differences between us
and upstream.
Change-Id: I217fecee64c7e6bac9272486d0cc334e192b501e
Reviewed-on: https://code.wireshark.org/review/11253
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lemon/lemon.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index acbdd129ec..e091d2419a 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -2707,7 +2707,7 @@ void Parse(struct lemon *gp) filesize = ftell(fp); rewind(fp); filebuf = (char *)malloc( filesize+1 ); - if( filesize>100000000 || filebuf==NULL ){ + if( filesize>100000000 || filebuf==0 ){ ErrorMsg(ps.filename,0,"Input file too large."); gp->errorcnt++; free(filebuf); @@ -3174,10 +3174,9 @@ void ReportOutput(struct lemon *lemp) PRIVATE char *pathsearch(char *argv0, char *name, int modemask) { const char *pathlist; - char *pathbufptr = NULL; - char *pathbuf = NULL; - char *path = NULL; - char *cp; + char *pathbufptr; + char *pathbuf; + char *path,*cp; char c; #ifdef __WIN32__ @@ -3193,15 +3192,17 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask) *cp = c; }else{ pathlist = getenv("PATH"); - if( pathlist==NULL ) pathlist = ".:/bin:/usr/bin"; + if( pathlist==0 ) pathlist = ".:/bin:/usr/bin"; pathbuf = (char *) malloc( lemonStrlen(pathlist) + 1 ); + if( pathbuf == 0 ) + return NULL; pathbufptr = pathbuf; path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 ); - if( (pathbuf != NULL) && (path!=NULL) ){ + if( (path!=0) ){ lemon_strcpy(pathbuf, pathlist); while( *pathbuf ){ cp = strchr(pathbuf,':'); - if( cp==NULL ) cp = &pathbuf[lemonStrlen(pathbuf)]; + if( cp==0 ) cp = &pathbuf[lemonStrlen(pathbuf)]; c = *cp; *cp = 0; lemon_sprintf(path,"%s/%s",pathbuf,name); @@ -3211,10 +3212,8 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask) if( access(path,modemask)==0 ) break; } } - } - if (pathbufptr) free(pathbufptr); - + } return path; } |