context safties

and from Marauder, hardened filename entry for con::evaluate/compileexec. if the string forwarded along is not a real filename, consider it an eval block
This commit is contained in:
AzaezelX 2026-03-02 11:38:20 -06:00
parent 19d8a5525d
commit 80f62573fe
8 changed files with 21 additions and 18 deletions

View file

@ -229,12 +229,12 @@ bool SubScene::evaluateCondition()
if (objectName != NULL) if (objectName != NULL)
objectName = getIdString(); objectName = getIdString();
StringTableEntry groupName = getGroup()->getName(); StringTableEntry groupName = getGroup() ? getGroup()->getName() : NULL;
if (groupName != NULL) if (groupName != NULL)
groupName = getGroup()->getIdString(); groupName = getGroup()->getIdString();
String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName); String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName);
Con::evaluate(command.c_str(), false, context); Con::evaluate(command.c_str(), false, context.c_str());
return Con::getBoolVariable(resVar.c_str()); return Con::getBoolVariable(resVar.c_str());
} }
return true; return true;

View file

@ -372,12 +372,12 @@ bool SpawnSphere::testCondition()
if (objectName != NULL) if (objectName != NULL)
objectName = getIdString(); objectName = getIdString();
StringTableEntry groupName = getGroup()->getName(); StringTableEntry groupName = getGroup() ? getGroup()->getName() : NULL;
if (groupName != NULL) if (groupName != NULL)
groupName = getGroup()->getIdString(); groupName = getGroup()->getIdString();
String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName); String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName);
Con::evaluate(command.c_str(), false, context); Con::evaluate(command.c_str(), false, context.c_str());
if (Con::getBoolVariable(resVar.c_str()) == 1) if (Con::getBoolVariable(resVar.c_str()) == 1)
{ {
return true; return true;

View file

@ -711,12 +711,12 @@ bool Trigger::testCondition()
if (objectName != NULL) if (objectName != NULL)
objectName = getIdString(); objectName = getIdString();
StringTableEntry groupName = getGroup()->getName(); StringTableEntry groupName = getGroup() ? getGroup()->getName() : NULL;
if (groupName != NULL) if (groupName != NULL)
groupName = getGroup()->getIdString(); groupName = getGroup()->getIdString();
String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName); String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName);
Con::evaluate(command.c_str(), false, context); Con::evaluate(command.c_str(), false, context.c_str());
if (Con::getBoolVariable(resVar.c_str()) == 1) if (Con::getBoolVariable(resVar.c_str()) == 1)
{ {
return true; return true;
@ -817,7 +817,7 @@ void Trigger::processTick(const Move* move)
if (objectName != NULL) if (objectName != NULL)
objectName = getIdString(); objectName = getIdString();
StringTableEntry groupName = getGroup()->getName(); StringTableEntry groupName = getGroup() ? getGroup()->getName() : NULL;
if (groupName != NULL) if (groupName != NULL)
groupName = getGroup()->getIdString(); groupName = getGroup()->getIdString();

View file

@ -611,7 +611,7 @@ Con::EvalResult CodeBlock::compileExec(StringTableEntry fileName, const char *in
Script::gStatementList = NULL; Script::gStatementList = NULL;
// we are an eval compile if we don't have a file name associated (no exec) // we are an eval compile if we don't have a file name associated (no exec)
gIsEvalCompile = fileName == NULL; gIsEvalCompile = fileName == NULL || setFrame == 0;
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars; gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars;
// Set up the parser. // Set up the parser.

View file

@ -38,8 +38,10 @@ namespace TorqueScript
if (fileName) if (fileName)
fileName = StringTable->insert(fileName); fileName = StringTable->insert(fileName);
bool fileExec = Torque::FS::IsFile(fileName);
CodeBlock* newCodeBlock = new CodeBlock(); CodeBlock* newCodeBlock = new CodeBlock();
return (newCodeBlock->compileExec(fileName, string, false, fileName ? -1 : 0)); return (newCodeBlock->compileExec(fileName, string, false, fileExec ? -1 : 0));
} }
Con::EvalResult TorqueScriptRuntime::evaluate(const char* script, S32 frame, bool echo, const char* fileName) Con::EvalResult TorqueScriptRuntime::evaluate(const char* script, S32 frame, bool echo, const char* fileName)

View file

@ -976,7 +976,7 @@ void GuiGameListMenuCtrl::doScriptCommand(StringTableEntry command)
setThisControl(); setThisControl();
StringTableEntry objectName = getName() != StringTable->EmptyString() ? getName() : getInternalName(); StringTableEntry objectName = getName() != StringTable->EmptyString() ? getName() : getInternalName();
String context = String::ToString("%s\nObject: %s", Platform::makeRelativePathName(getFilename(), NULL), objectName); String context = String::ToString("%s\nObject: %s", Platform::makeRelativePathName(getFilename(), NULL), objectName);
Con::evaluate(command, false, context); Con::evaluate(command, false, context.c_str());
} }
} }

View file

@ -1541,7 +1541,7 @@ StringTableEntry GuiListBoxCtrl::_makeMirrorItemName( SimObject *inObj )
StringTableEntry objectName = getName() != StringTable->EmptyString() ? getName() : getInternalName(); StringTableEntry objectName = getName() != StringTable->EmptyString() ? getName() : getInternalName();
String context = String::ToString("%s, Object: %s", Platform::makeRelativePathName(getFilename(), NULL), objectName); String context = String::ToString("%s, Object: %s", Platform::makeRelativePathName(getFilename(), NULL), objectName);
outName = StringTable->insert( Con::evaluate( mMakeNameCallback, false, context).value, true ); outName = StringTable->insert( Con::evaluate( mMakeNameCallback, false, context.c_str()).value, true );
} }
else if ( inObj->getName() ) else if ( inObj->getName() )
outName = StringTable->insert( inObj->getName() ); outName = StringTable->insert( inObj->getName() );

View file

@ -2496,14 +2496,15 @@ const char* GuiControl::evaluate( const char* str )
{ {
smThisControl = this; smThisControl = this;
StringTableEntry objectName = getName(); StringTableEntry objectName = getName();
if (getName() == NULL) if (objectName != NULL)
objectName = getInternalName(); objectName = getIdString();
StringTableEntry fileName = getFilename();
if (fileName != NULL)
fileName = Platform::makeRelativePathName(fileName, NULL);
String context = String::ToString("%s\nObject: %s", fileName, objectName); StringTableEntry groupName = getGroup() ? getGroup()->getName() : NULL;
const char* result = Con::evaluate(str, false, context).value; if (groupName != NULL)
groupName = getGroup()->getIdString();
String context = String::ToString("%s\nGroup: %s, Object: %s", getFilename(), groupName, objectName);
const char* result = Con::evaluate(str, false, context.c_str()).value;
smThisControl = NULL; smThisControl = NULL;
return result; return result;