Skip to content

Commit

Permalink
Add script function name length check
Browse files Browse the repository at this point in the history
Should fix #440
  • Loading branch information
MegAmi24 committed Sep 29, 2024
1 parent 48c5f60 commit ecf9549
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
63 changes: 63 additions & 0 deletions RSDKv4/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,27 @@ void ParseScriptFile(char *scriptName, int scriptID)
}

if (scriptFunctionCount < FUNCTION_COUNT && funcID == -1) {
#if !RETRO_USE_ORIGINAL_CODE
if (StrLength(funcName) >= FUNCTION_NAME_LIMIT) {
SetupTextMenu(&gameMenu[0], 0);
AddTextMenuEntry(&gameMenu[0], "SCRIPT PARSING FAILED");
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "FUNCTION NAME TOO LONG");
AddTextMenuEntry(&gameMenu[0], funcName);
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "LINE NUMBER");
char buffer[0x10];
buffer[0] = 0;
AppendIntegerToString(buffer, lineID);
AddTextMenuEntry(&gameMenu[0], buffer);
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "ERROR IN");
AddTextMenuEntry(&gameMenu[0], scriptName);
Engine.gameMode = ENGINE_SCRIPTERROR;
return;
}
#endif

StrCopy(scriptFunctionList[scriptFunctionCount++].name, funcName);
}
else {
Expand All @@ -2902,6 +2923,27 @@ void ParseScriptFile(char *scriptName, int scriptID)
parseMode = PARSEMODE_SCOPELESS;
}
else {
#if !RETRO_USE_ORIGINAL_CODE
if (StrLength(funcName) >= FUNCTION_NAME_LIMIT) {
SetupTextMenu(&gameMenu[0], 0);
AddTextMenuEntry(&gameMenu[0], "SCRIPT PARSING FAILED");
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "FUNCTION NAME TOO LONG");
AddTextMenuEntry(&gameMenu[0], funcName);
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "LINE NUMBER");
char buffer[0x10];
buffer[0] = 0;
AppendIntegerToString(buffer, lineID);
AddTextMenuEntry(&gameMenu[0], buffer);
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "ERROR IN");
AddTextMenuEntry(&gameMenu[0], scriptName);
Engine.gameMode = ENGINE_SCRIPTERROR;
return;
}
#endif

StrCopy(scriptFunctionList[scriptFunctionCount].name, funcName);
scriptFunctionList[scriptFunctionCount].access = ACCESS_PUBLIC;
scriptFunctionList[scriptFunctionCount].ptr.scriptCodePtr = scriptCodePos;
Expand Down Expand Up @@ -2940,6 +2982,27 @@ void ParseScriptFile(char *scriptName, int scriptID)
parseMode = PARSEMODE_SCOPELESS;
}
else {
#if !RETRO_USE_ORIGINAL_CODE
if (StrLength(funcName) >= FUNCTION_NAME_LIMIT) {
SetupTextMenu(&gameMenu[0], 0);
AddTextMenuEntry(&gameMenu[0], "SCRIPT PARSING FAILED");
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "FUNCTION NAME TOO LONG");
AddTextMenuEntry(&gameMenu[0], funcName);
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "LINE NUMBER");
char buffer[0x10];
buffer[0] = 0;
AppendIntegerToString(buffer, lineID);
AddTextMenuEntry(&gameMenu[0], buffer);
AddTextMenuEntry(&gameMenu[0], " ");
AddTextMenuEntry(&gameMenu[0], "ERROR IN");
AddTextMenuEntry(&gameMenu[0], scriptName);
Engine.gameMode = ENGINE_SCRIPTERROR;
return;
}
#endif

StrCopy(scriptFunctionList[scriptFunctionCount].name, funcName);
scriptFunctionList[scriptFunctionCount].access = ACCESS_PRIVATE;
scriptFunctionList[scriptFunctionCount].ptr.scriptCodePtr = scriptCodePos;
Expand Down
4 changes: 3 additions & 1 deletion RSDKv4/Script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define FUNCSTACK_COUNT (0x400)
#define FORSTACK_COUNT (0x400)

#define FUNCTION_NAME_LIMIT (0x20)

#define RETRO_USE_COMPILER (1)

struct ScriptPtr {
Expand All @@ -20,7 +22,7 @@ struct ScriptFunction {

byte access;
#if RETRO_USE_COMPILER
char name[0x20];
char name[FUNCTION_NAME_LIMIT];
#endif
ScriptPtr ptr;
};
Expand Down

0 comments on commit ecf9549

Please sign in to comment.