Skip to content

Commit 70cf45b

Browse files
committed
Sanitize the % symbol when logging mod (directory) names to log.txt
(cherry picked from commit 6b42fc3)
1 parent baf2076 commit 70cf45b

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

libzhl/IsaacRepentance_static.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "IsaacRepentance.h"
22
#include "Log.h"
33
#include <cmath>
4+
#include <regex>
45

56
bool Room::IsValidRailType(int rail) {
67
if (rail < 0 || rail > RailType::RAIL_NONE) {
@@ -463,6 +464,11 @@ void KAGE::_LogMessage(int flag, const char* fmt, ...) {
463464
}
464465
}
465466

467+
// Sanitizes the % character from the provided string to make sure it is not interpreted as a format specifier.
468+
void KAGE::SafeLogMessage(int flag, const char* nonFormatString) {
469+
LogMessage(flag, std::regex_replace(nonFormatString, std::regex("%"), "%%").c_str());
470+
}
471+
466472
std::optional<std::string> KAGE_Filesys_ContentManager::GetMountedFilePath(const char* filePath) {
467473
const char* rawPath = GetMountedFilePath_DeleteMe(filePath);
468474
if (rawPath) {

libzhl/functions/KAGE.zhl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ static cleanup void KAGE::LogMessage(int flag, const char* string);
66
struct KAGE {
77
{{
88
LIBZHL_API static void _LogMessage(int flag, const char* fmt, ...);
9+
LIBZHL_API static void SafeLogMessage(int flag, const char* nonFormatString);
910
}}
1011
} : 0;

repentogon/Patches/XMLData.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void UpdateXMLModEntryData() {
380380
XMLStuff.ModData->byfullpath[mod["fulldirectory"]] = idx;
381381

382382
}
383-
KAGE::LogMessage(0, enabledmodslist.c_str());
383+
KAGE::SafeLogMessage(0, enabledmodslist.c_str());
384384
KAGE::LogMessage(0, "-- Enabled Mods END -- \n");
385385
}
386386

@@ -2544,7 +2544,7 @@ void ProcessXmlNode(xml_node<char>* node,bool force = false) {
25442544
XMLStuff.ModData->byorder[XMLStuff.ModData->nodes.size()] = id;
25452545

25462546
string loadingmodmsg = "Loading: " + mod["directory"] + "(" + mod["id"] + ") \n";
2547-
KAGE::LogMessage(0, loadingmodmsg.c_str());
2547+
KAGE::SafeLogMessage(0, loadingmodmsg.c_str());
25482548
}
25492549
break;
25502550
case 26: //fxlayers
@@ -2571,7 +2571,7 @@ HOOK_METHOD(xmlnode_rep, first_node, (char* name, int size, bool casesensitive)-
25712571
if ((currpath.length() > 0) && (err != nullptr)){
25722572
string error = "[XMLError] " + xmlerrors[toint(err->value())] + " in " + currpath;
25732573
g_Game->GetConsole()->PrintError(error);
2574-
KAGE::LogMessage(3,(error + "\n").c_str());
2574+
KAGE::SafeLogMessage(3,(error + "\n").c_str());
25752575
//ZHL::Log("%s \n", error.c_str());
25762576
}
25772577
ProcessXmlNode(node);

repentogon/Patches/XMLData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ inline bool XMLParse(xml_document<char>* xmldoc, char* xml, const string& dir) {
10061006
string reason = err.what() + string(" at line ") + to_string(lineNumber);
10071007
string error = "[XMLError] " + reason + " in " + dir;
10081008
g_Game->GetConsole()->PrintError(error);
1009-
KAGE::LogMessage(3, (error + "\n").c_str());
1009+
KAGE::SafeLogMessage(3, (error + "\n").c_str());
10101010
//printf("%s \n", error.c_str());
10111011
//mclear(xmldoc);
10121012
}

0 commit comments

Comments
 (0)