WebParser: Fixed that RegExp matching fails if data contains embedded NULLs

This commit is contained in:
Birunthan Mohanathas 2011-09-24 13:54:24 +00:00
parent e3bde6879b
commit 8ca0d0a830

View File

@ -75,7 +75,7 @@ void ShowError(int lineNumber, WCHAR* errorMsg = NULL);
unsigned __stdcall NetworkThreadProc(void* pParam); unsigned __stdcall NetworkThreadProc(void* pParam);
unsigned __stdcall NetworkDownloadThreadProc(void* pParam); unsigned __stdcall NetworkDownloadThreadProc(void* pParam);
void Log(int level, const WCHAR* string); void Log(int level, const WCHAR* string);
void ParseData(UrlData* urlData, LPCSTR parseData); void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize);
CRITICAL_SECTION g_CriticalSection; CRITICAL_SECTION g_CriticalSection;
bool g_Initialized = false; bool g_Initialized = false;
@ -828,7 +828,7 @@ unsigned __stdcall NetworkThreadProc(void* pParam)
} }
} }
ParseData(urlData, (LPCSTR)data); ParseData(urlData, (LPCSTR)data, dwSize);
delete [] data; delete [] data;
} }
@ -841,10 +841,8 @@ unsigned __stdcall NetworkThreadProc(void* pParam)
return 0; // thread completed successfully return 0; // thread completed successfully
} }
void ParseData(UrlData* urlData, LPCSTR parseData) void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
{ {
size_t dwSize = 0;
// Parse the value from the data // Parse the value from the data
pcre* re; pcre* re;
const char* error; const char* error;
@ -884,8 +882,6 @@ void ParseData(UrlData* urlData, LPCSTR parseData)
parseData = utf8Data.c_str(); parseData = utf8Data.c_str();
} }
dwSize = strlen(parseData);
rc = pcre_exec( rc = pcre_exec(
re, // the compiled pattern re, // the compiled pattern
NULL, // no extra data - we didn't study the pattern NULL, // no extra data - we didn't study the pattern
@ -987,7 +983,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData)
// Change the index and parse the substring // Change the index and parse the substring
int index = (*i).second->stringIndex; int index = (*i).second->stringIndex;
(*i).second->stringIndex = (*i).second->stringIndex2; (*i).second->stringIndex = (*i).second->stringIndex2;
ParseData((*i).second, szResult.c_str()); ParseData((*i).second, szResult.c_str(), szResult.length());
(*i).second->stringIndex = index; (*i).second->stringIndex = index;
} }
else else