Skip to content

Commit

Permalink
Fix __FILE__ when filename contains quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedKoS authored Sep 10, 2020
1 parent 304bb9f commit 34c2288
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/asm/fstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,26 @@ void fstk_Init(char *pFileName)
{
char tzSymFileName[_MAX_PATH + 1 + 2];

snprintf(tzSymFileName, sizeof(tzSymFileName), "\"%s\"", pFileName);
char *c = pFileName;
int fileNameIndex = 0;

tzSymFileName[fileNameIndex++] = '"';

// minus 2 to account for trailing "\"\0"
// minus 1 to avoid a buffer overflow in extreme cases
while (*c && fileNameIndex < sizeof(tzSymFileName) - 2 - 1) {

if (*c == '"') {
tzSymFileName[fileNameIndex++] = '\\';
}

tzSymFileName[fileNameIndex++] = *c;
++c;
}

tzSymFileName[fileNameIndex++] = '"';
tzSymFileName[fileNameIndex] = '\0';

sym_AddString("__FILE__", tzSymFileName);

pFileStack = NULL;
Expand Down

0 comments on commit 34c2288

Please sign in to comment.