Skip to content

Commit

Permalink
Fix potential null pointer derefs with ConfigFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jp9000 committed Jan 24, 2015
1 parent 8b6d936 commit 6a6b010
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions OBSApi/Utility/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ BOOL ConfigFile::LoadFile(DWORD dwOpenMode)
lpTempFileData[dwLength+4] = 0;
file.Close();

if (!lpFileData)
lpFileData = (TSTR)new InternalUselessStuff;

lpActualFileData = utf8_createTstr(lpTempFileData);
dwLength = slen(lpActualFileData);
Free(lpTempFileData);
Expand Down Expand Up @@ -231,6 +234,9 @@ void ConfigFile::Close()

BOOL ConfigFile::SaveAs(CTSTR lpPath)
{
if (!bOpen || !lpFileData)
return false;

OSEnterMutex(hHorribleThreadSafetyMutex);
XFile newFile;

Expand Down Expand Up @@ -272,6 +278,9 @@ void ConfigFile::SetFilePath(CTSTR lpPath)

String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def)
{
if (!bOpen || !lpFileData)
return String(def);

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -305,6 +314,9 @@ String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def)

CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def)
{
if (!bOpen || !lpFileData)
return def;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -338,6 +350,9 @@ CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def)

int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def)
{
if (!bOpen || !lpFileData)
return def;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -383,6 +398,9 @@ int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def)

DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def)
{
if (!bOpen || !lpFileData)
return def;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -412,6 +430,9 @@ DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def)

float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def)
{
if (!bOpen || !lpFileData)
return def;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -441,6 +462,9 @@ float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def)

Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)
{
if (!bOpen || !lpFileData)
return Color4(0.0f, 0.0f, 0.0f, 0.0f);

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -525,6 +549,9 @@ Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)

BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList)
{
if (!bOpen || !lpFileData)
return false;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -558,6 +585,9 @@ BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList

BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List<int> &IntList)
{
if (!bOpen || !lpFileData)
return false;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -600,6 +630,9 @@ BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List<int> &IntList)

BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List<float> &FloatList)
{
if (!bOpen || !lpFileData)
return false;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down Expand Up @@ -632,6 +665,9 @@ BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List<float> &FloatLi

BOOL ConfigFile::GetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorList)
{
if (!bOpen || !lpFileData)
return false;

OSEnterMutex(hHorribleThreadSafetyMutex);
assert(lpSection);
assert(lpKey);
Expand Down

0 comments on commit 6a6b010

Please sign in to comment.