mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-09 18:39:45 +01: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:
parent
0da9b5069a
commit
69b0f0b650
1 changed files with 30 additions and 0 deletions
|
@ -292,6 +292,11 @@ void Game::init(void)
|
||||||
const char* pKey = pElem->Value();
|
const char* pKey = pElem->Value();
|
||||||
const char* pText = pElem->GetText() ;
|
const char* pText = pElem->GetText() ;
|
||||||
|
|
||||||
|
if (pText == NULL)
|
||||||
|
{
|
||||||
|
pText = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_strcmp(pKey, "summary") == 0)
|
if (SDL_strcmp(pKey, "summary") == 0)
|
||||||
{
|
{
|
||||||
quicksummary = pText;
|
quicksummary = pText;
|
||||||
|
@ -332,6 +337,11 @@ void Game::init(void)
|
||||||
const char* pKey = pElem->Value();
|
const char* pKey = pElem->Value();
|
||||||
const char* pText = pElem->GetText() ;
|
const char* pText = pElem->GetText() ;
|
||||||
|
|
||||||
|
if (pText == NULL)
|
||||||
|
{
|
||||||
|
pText = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_strcmp(pKey, "summary") == 0)
|
if (SDL_strcmp(pKey, "summary") == 0)
|
||||||
{
|
{
|
||||||
telesummary = pText;
|
telesummary = pText;
|
||||||
|
@ -4016,6 +4026,11 @@ void Game::loadstats(ScreenSettings* screen_settings)
|
||||||
const char* pKey = pElem->Value();
|
const char* pKey = pElem->Value();
|
||||||
const char* pText = pElem->GetText() ;
|
const char* pText = pElem->GetText() ;
|
||||||
|
|
||||||
|
if (pText == NULL)
|
||||||
|
{
|
||||||
|
pText = "";
|
||||||
|
}
|
||||||
|
|
||||||
LOAD_ARRAY(unlock)
|
LOAD_ARRAY(unlock)
|
||||||
|
|
||||||
LOAD_ARRAY(unlocknotify)
|
LOAD_ARRAY(unlocknotify)
|
||||||
|
@ -4073,6 +4088,11 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
|
||||||
const char* pKey = pElem->Value();
|
const char* pKey = pElem->Value();
|
||||||
const char* pText = pElem->GetText();
|
const char* pText = pElem->GetText();
|
||||||
|
|
||||||
|
if (pText == NULL)
|
||||||
|
{
|
||||||
|
pText = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_strcmp(pKey, "fullscreen") == 0)
|
if (SDL_strcmp(pKey, "fullscreen") == 0)
|
||||||
{
|
{
|
||||||
screen_settings->fullscreen = help.Int(pText);
|
screen_settings->fullscreen = help.Int(pText);
|
||||||
|
@ -5132,6 +5152,11 @@ void Game::loadsummary(void)
|
||||||
const char* pKey = pElem->Value();
|
const char* pKey = pElem->Value();
|
||||||
const char* pText = pElem->GetText() ;
|
const char* pText = pElem->GetText() ;
|
||||||
|
|
||||||
|
if (pText == NULL)
|
||||||
|
{
|
||||||
|
pText = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_strcmp(pKey, "summary") == 0)
|
if (SDL_strcmp(pKey, "summary") == 0)
|
||||||
{
|
{
|
||||||
telesummary = pText;
|
telesummary = pText;
|
||||||
|
@ -5209,6 +5234,11 @@ void Game::loadsummary(void)
|
||||||
const char* pKey = pElem->Value();
|
const char* pKey = pElem->Value();
|
||||||
const char* pText = pElem->GetText() ;
|
const char* pText = pElem->GetText() ;
|
||||||
|
|
||||||
|
if (pText == NULL)
|
||||||
|
{
|
||||||
|
pText = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_strcmp(pKey, "summary") == 0)
|
if (SDL_strcmp(pKey, "summary") == 0)
|
||||||
{
|
{
|
||||||
quicksummary = pText;
|
quicksummary = pText;
|
||||||
|
|
Loading…
Reference in a new issue