Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…] Fix broken config parsing in ChakraFull

Merge pull request #3684 from digitalinfinity:config_fix

ChakraFull had ifdef-ed the value of FINISHED. When the config parsing code was changed to use fget*c instead of fwscanf, the ifdef should have been removed. Not doing so caused us to fill in EOFs in the config buffer causing us to incorrectly parse the config file.

This change removes the old version of FINISHED and switches to using EOF or WEOF depending on the platform.
  • Loading branch information
chakrabot authored and MSLaguana committed Sep 25, 2017
1 parent 2d6277d commit 270d15f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 6 additions & 4 deletions deps/chakrashim/core/lib/Common/Core/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,12 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
#define ReadChar(file) fgetwc(file)
#define UnreadChar(c, file) ungetwc(c, file)
#define CharType wint_t
#define EndChar WEOF
#else
#define ReadChar(file) fgetc(file)
#define UnreadChar(c, file) ungetc(c, file)
#define CharType int
#define EndChar EOF
#endif

// We don't expect the token to overflow- if it does
Expand All @@ -390,22 +392,21 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
while (index < MaxTokenSize)
{
CharType curChar = ReadChar(configFile);
const CharType end = static_cast<const CharType>(FINISHED);

if (curChar == end || isspace(curChar))
if (curChar == EndChar || isspace(curChar))
{
configBuffer[index] = 0;
if ((err = parser.Parse(configBuffer)) != 0)
{
break;
}

while(curChar != end && isspace(curChar))
while(curChar != EndChar && isspace(curChar))
{
curChar = ReadChar(configFile);
}

if (curChar == end)
if (curChar == EndChar)
{
break;
}
Expand All @@ -428,6 +429,7 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
#undef ReadChar
#undef UnreadChar
#undef CharType
#undef EndChar

fclose(configFile);

Expand Down
8 changes: 0 additions & 8 deletions deps/chakrashim/core/lib/Common/Core/ConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ class ConfigParser
const LPCWSTR _configFileName;
CLANG_WNO_END

// NT version of CRT has the "backward compat" behavior that returns 0 instead of EOF
// for unicode version of fwscanf.
#ifdef NTBUILD
static const int FINISHED = 0;
#else
static const int FINISHED = EOF;
#endif

void ParseRegistryKey(HKEY hk, CmdLineArgsParser &parser);

public:
Expand Down

0 comments on commit 270d15f

Please sign in to comment.