Skip to content

Use platform limits for include file name buffer size #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ LOCAL RC FC ppcDoI( // decode/execute preprocessor command inner. call ppctIni(
// returned error code other than RCFATAL ignored by caller
{
SI c, c1, c2, value, noCheckEnd = 0;
char fnBuf[81], ppcWord[1+32+1], *q;
char ppcWord[1+32+1], *q;
RC rc;

// syntax verify beginning of command
Expand Down Expand Up @@ -3113,21 +3113,22 @@ elifJoins: ; // set compile on or off per 'value'
if (strchr( "<\"", c1)==NULL)
return ppErr( MH_P0038); // "'<' or '\"' expected"
c2 = (c1 == '<') ? '>' : c1;
for (q = fnBuf; ; ) // scan/copy file name
char file_name_buffer[CSE_MAX_PATH];
for (q = file_name_buffer; ; ) // scan/copy file name
{
c = ppCNdc(); // get char NOT DECOMMENTED
if (c==c2) // if expected terminator
break;
if (c==EOF) // if end of input
return ppErr( MH_P0045, c2); // "Closing '%c' not found"
if (q < fnBuf + sizeof(fnBuf)-1) // truncate at bufSize
if (q < file_name_buffer + sizeof(file_name_buffer)-1) // truncate at bufSize
*q++ = (char)c; // copy name so can terminate
}
*q = 0;
CHECKEND; // now: after open, errmsg wd have wrong file
// execute #include
// filename syntax check worth the bother?
if (ppOpI( fnBuf, ".inp") ) // open incl file, pp.cpp
if (ppOpI( file_name_buffer, ".inp") ) // open incl file, pp.cpp
return RCBAD; // if file not found or out of memory
break;

Expand Down