Add safeguards against string overflows

Use snprintf instead of other unsafe functions. That way it is possible
to limit the size of the buffer and to ensure that it never overflows.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
Antonio Niño Díaz
2018-01-08 00:14:44 +00:00
parent 0e0e12a769
commit 2a97535e75
3 changed files with 49 additions and 24 deletions

View File

@@ -347,7 +347,7 @@ void fstk_RunMacroArg(int32_t s)
pushcontext();
nCurrentStatus = STAT_isMacroArg;
sprintf(tzCurrentFileName, "%c", (uint8_t)s);
snprintf(tzCurrentFileName, _MAX_PATH + 1, "%c", (uint8_t)s);
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
yy_switch_to_buffer(CurrentFlexHandle);
}
@@ -410,7 +410,7 @@ void fstk_Init(char *s)
nMacroCount = 0;
nCurrentStatus = STAT_isInclude;
strcpy(tzCurrentFileName, tzFileName);
snprintf(tzCurrentFileName, _MAX_PATH + 1, "%s", tzFileName);
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle);
nLineNo = 1;