From: kvigor Date: Wed, 26 Feb 2003 04:13:56 +0000 (+0000) Subject: buffer overflow caught: preOutCmd could exceed PATH_MAX (observed on Cygwin building... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=18b41f24eb98016da2b638dbdc72a96a40b389f1;p=fw%2Fsdcc buffer overflow caught: preOutCmd could exceed PATH_MAX (observed on Cygwin building regression tests) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2316 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 4be02db9..cfbacf6c 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -283,9 +283,9 @@ extern int NestLevel; /* NestLevel SDCC.y */ extern int stackPtr; /* stack pointer SDCC.y */ extern int xstackPtr; /* external stack pointer SDCC.y */ extern int reentrant; /* /X flag has been sent SDCC.y */ -extern char buffer[PATH_MAX]; /* general buffer SDCCmain.c */ -extern int currRegBank; /* register bank being used SDCCgens.c */ -extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */ +extern char buffer[PATH_MAX * 2];/* general buffer SDCCmain.c */ +extern int currRegBank; /* register bank being used SDCCgens.c */ +extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */ extern struct symbol *currFunc; /* current function SDCCgens.c */ extern int cNestLevel; /* block nest level SDCCval.c */ extern int currBlockno; /* sequentail block number */ diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 8b41cce7..39655777 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -87,7 +87,7 @@ int ds390_jammed = 0; // Globally accessible scratch buffer for file names. char scratchFileName[PATH_MAX]; -char buffer[PATH_MAX]; +char buffer[PATH_MAX * 2]; // In MSC VC6 default search path for exe's to path for this @@ -560,7 +560,7 @@ processFile (char *s) } /* copy the file name into the buffer */ - strncpyz (buffer, s, PATH_MAX); + strncpyz (buffer, s, sizeof(buffer)); /* get rid of the "."-extension */ @@ -1032,7 +1032,8 @@ parseCmdLine (int argc, char **argv) char *p; /* copy the file name into the buffer */ - strncpyz(buffer, getStringArg("-o", argv, &i, argc), PATH_MAX); + strncpyz(buffer, getStringArg("-o", argv, &i, argc), + sizeof(buffer)); /* point to last character */ p = buffer + strlen (buffer) - 1; if (*p == DIR_SEPARATOR_CHAR) @@ -1213,7 +1214,7 @@ parseCmdLine (int argc, char **argv) char *objectName; size_t bufSize; - strncpyz (buffer, relFiles[0], PATH_MAX); + strncpyz (buffer, relFiles[0], sizeof(buffer)); /* remove extension (it must be .rel) */ *strrchr (buffer, '.') = '\0'; /* remove path */ @@ -1422,11 +1423,11 @@ linkEdit (char **envp) { char buffer2[PATH_MAX]; buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, NULL, NULL); - buildCmdLine2 (buffer, buffer2, PATH_MAX); + buildCmdLine2 (buffer, buffer2, sizeof(buffer)); } else { - buildCmdLine2 (buffer, port->linker.mcmd, PATH_MAX); + buildCmdLine2 (buffer, port->linker.mcmd, sizeof(buffer)); } system_ret = my_system (buffer); @@ -1501,8 +1502,9 @@ assemble (char **envp) strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName)); } else { /* the assembled file gets the name of the first modul */ - strncpyz (scratchFileName, dstFileName, PATH_MAX); - strncatz (scratchFileName, port->linker.rel_ext, PATH_MAX); + strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName)); + strncatz (scratchFileName, port->linker.rel_ext, + sizeof(scratchFileName)); } if (port->assembler.do_assemble) { @@ -1615,7 +1617,7 @@ preProcess (char **envp) if (options.verbose) printf ("sdcc: Calling preprocessor...\n"); - buildCmdLine2 (buffer, _preCmd, PATH_MAX); + buildCmdLine2 (buffer, _preCmd, sizeof(buffer)); if (my_system (buffer)) { @@ -1713,7 +1715,7 @@ _discoverPaths (const char *argv0) { getPathDifference (buffer, PREFIX, BINDIR); strncpyz (scratchFileName, getenv (SDCCDIR_NAME), sizeof(scratchFileName)); - strncatz (scratchFileName, buffer, PATH_MAX); + strncatz (scratchFileName, buffer, sizeof(scratchFileName)); setMainValue ("bindir", scratchFileName); ExePathList[0] = Safe_strdup (scratchFileName); }