OpenXRay / xray-16

Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. Join OpenXRay! ;)
https://discord.gg/sjRMQwv
Other
3.02k stars 454 forks source link

On Linux, quick save are being created in a subfolder instead of game saves folder #1536

Closed Xottab-DUTY closed 7 months ago

Xottab-DUTY commented 12 months ago

Describe the bug When you use a quick save, the file name is <system name> - quicksave.<fmt>, where \<system name> is the user profile name in the OS and \<fmt> is file format – either scop or sav.

For some reason, when we try to save a file with path game folder/_appdata_/savedgames/user - quicksave.scop, the result appears to be game folder/_appdata_/gamesaves/user/- quicksave.scop – it creates a subfolder.

To Reproduce Steps to reproduce the behavior:

  1. Use a quick save
  2. See the bug

Expected behavior Quick saves should be saved into savedgames folder normally.

Screenshots, videos image image

Desktop (please complete the following information):

Additional context Look at function CALifeStorageManager::save in xrGame/alife_storage_manager.cpp

Xottab-DUTY commented 12 months ago

@AMS21, could you look?

AMS21 commented 12 months ago

I've tried to replicate this but it works as expected on my machine. From what I've gathered while looking at the code I would assume that for some reason Core.UserName contains a trailing backslash as I can replicate this behavior by hard coding the name like this

diff --git a/src/xrCore/xrCore.cpp b/src/xrCore/xrCore.cpp
index bf0389127..395075f59 100644
--- a/src/xrCore/xrCore.cpp
+++ b/src/xrCore/xrCore.cpp
@@ -228,7 +228,7 @@ void xrCore::Initialize(pcstr _ApplicationName, pcstr commandLine, LogCallback c
         struct passwd *pw = getpwuid(uid);
         if(pw)
         {
-            strcpy(UserName, pw->pw_gecos);
+            strcpy(UserName, "lucy\\");
             char* pos = strchr(UserName, ','); // pw_gecos return string
             if(NULL != pos)
                 *pos = 0;

What I'm not sure how this backslash got in there in the first place, since I don't believe having a backslash in your username is allowed but I might be wrong here.

If that's the case one potential fix could be after setting UserName to go and replace all backslashes or other problematic characters with _.

I also notices that since we are using strcpy you could potentially overflow the buffer by having a username which is longer than 64 characters, which could easily be fixed by using strncpy.

Xottab-DUTY commented 7 months ago

In theory, this is fixed. We can reopen if it's not.