Tier1: properly handle null string values in ConVar::InternalSetValue

There is code that checks if the given string is nullptr, and if so, sets it to an empty string (""). But this new pointer wasn't used on InternalSetColorFromString and atof. InternalSetColorFromString calls sscanf on the given string which if null, is undefined behavior.

The bug was also present in the engine code, this has been patched on assembly level and confirmed correct.
This commit is contained in:
Kawe Mazidjatari 2025-01-24 02:12:48 +01:00
parent 291a99e3ae
commit bf7f128acf
2 changed files with 4 additions and 4 deletions

View File

@ -103,7 +103,7 @@ public:
// Utilities for convars accessed by the material system thread
virtual bool IsMaterialThreadSetAllowed() const = 0;
virtual void QueueMaterialThreadSetValue(ConVar* pConVar, const char* pValue) = 0;
virtual void QueueMaterialThreadSetValue(ConVar* pConVar, const char* pValue/*pValue is allowed to be null*/) = 0;
virtual void QueueMaterialThreadSetValue(ConVar* pConVar, int nValue) = 0;
virtual void QueueMaterialThreadSetValue(ConVar* pConVar, float flValue) = 0;
virtual bool HasQueuedMaterialThreadConVarSets() const = 0;

View File

@ -659,13 +659,13 @@ void ConVar::InternalSetValue(const char* value)
if (!newVal)
newVal = "";
if (!InternalSetColorFromString(value))
if (!InternalSetColorFromString(newVal))
{
// Not a color, do the standard thing
float fNewValue = (float)atof(value);
float fNewValue = (float)atof(newVal);
if (!IsFinite(fNewValue))
{
DevWarning(eDLL_T::COMMON, "Warning: %s = '%s' is infinite, clamping value.\n", GetName(), value);
DevWarning(eDLL_T::COMMON, "Warning: %s = '%s' is infinite, clamping value.\n", GetName(), newVal);
fNewValue = FLT_MAX;
}