Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate player/item names coming from save file #7779

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

StephenCWills
Copy link
Member

When reviewing #7775, I noticed the code is just blindly assuming that LoadHelper::NextBytes() will produce a null-terminated string in Item::_iName, Item::_iIName and Player::_pName, but the function provides no such guarantee.

I was able to observe a buffer overrun with single_0.sv.zip, using some debug code to visualize it. The player name is completely full of the s character. The debug code writes i characters into the item seed for the player's head slot so they can be seen in the output.

diff --git a/Source/diablo.cpp b/Source/diablo.cpp
index 6664a2199..fbb866c0b 100644
--- a/Source/diablo.cpp
+++ b/Source/diablo.cpp
@@ -1991,6 +1991,11 @@ void InitKeymapActions()
 	    'X',
 	    [] {
 		    DebugToggle = !DebugToggle;
+		    MyPlayer->InvBody[0]._iSeed = DebugToggle ? 0x00696969 : 0;
+		    EventPlrMsg(fmt::format(
+		                    fmt::runtime("{:s}"),
+		                    MyPlayer->_pName),
+		        UiFlags::ColorWhite);
 	    });
 #endif
 	options.Keymapper.CommitActions();

Here's what that looks like when I press x four times.

image

And to demonstrate how non-debug code makes the assumption about null termination, here is an example of that.

image

@kphoenix137
Copy link
Collaborator

Back when I was messing around with a custom character renaming command in DevilutionX, I noticed I could corrupt other data if I made the name too long. Unfortunately it didn't occur to me to actually do something about it. :')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants