1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 05:58:30 +02:00

Add missing pText NULL checks

If an XML tag doesn't contain anything inside, pText will be NULL. If
that happens without being checked, then NULL will be passed to
SDL_strcmp(). SDL_strcmp() will either call libc strcmp() or use its own
implementation; both implementations will still dereference the NULL
without checking it.

This is undefined behavior, so I'm fixing it. The solution is to do what
is done with all other XML parsing functions, and to make sure pText
gets set to a safe empty string (which is just a pointer to a null
terminator) if it happens to be NULL.
This commit is contained in:
Misa 2021-03-24 12:19:44 -07:00 committed by Ethan Lee
parent 0da9b5069a
commit 69b0f0b650

View File

@ -292,6 +292,11 @@ void Game::init(void)
const char* pKey = pElem->Value();
const char* pText = pElem->GetText() ;
if (pText == NULL)
{
pText = "";
}
if (SDL_strcmp(pKey, "summary") == 0)
{
quicksummary = pText;
@ -332,6 +337,11 @@ void Game::init(void)
const char* pKey = pElem->Value();
const char* pText = pElem->GetText() ;
if (pText == NULL)
{
pText = "";
}
if (SDL_strcmp(pKey, "summary") == 0)
{
telesummary = pText;
@ -4016,6 +4026,11 @@ void Game::loadstats(ScreenSettings* screen_settings)
const char* pKey = pElem->Value();
const char* pText = pElem->GetText() ;
if (pText == NULL)
{
pText = "";
}
LOAD_ARRAY(unlock)
LOAD_ARRAY(unlocknotify)
@ -4073,6 +4088,11 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
const char* pKey = pElem->Value();
const char* pText = pElem->GetText();
if (pText == NULL)
{
pText = "";
}
if (SDL_strcmp(pKey, "fullscreen") == 0)
{
screen_settings->fullscreen = help.Int(pText);
@ -5132,6 +5152,11 @@ void Game::loadsummary(void)
const char* pKey = pElem->Value();
const char* pText = pElem->GetText() ;
if (pText == NULL)
{
pText = "";
}
if (SDL_strcmp(pKey, "summary") == 0)
{
telesummary = pText;
@ -5209,6 +5234,11 @@ void Game::loadsummary(void)
const char* pKey = pElem->Value();
const char* pText = pElem->GetText() ;
if (pText == NULL)
{
pText = "";
}
if (SDL_strcmp(pKey, "summary") == 0)
{
quicksummary = pText;