tmp64 / BugfixedHL-Rebased

Bugfixed and improved Half-Life
GNU General Public License v3.0
108 stars 22 forks source link

Linux crash due to incorrect /proc/self/map parsing #172

Open serfreeman1337 opened 1 year ago

serfreeman1337 commented 1 year ago

On my "Arch Linux" machine I'm experiencing start up crash:

Core was generated by `/home/serfreeman1337/.local/share/Steam/steamapps/common/Half-Life/hl_linux -st'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0xd1927f6b in CEnginePatchesLinux::HookSvcHandlers (this=0xd1c6bec0 <s_EnginePatchesInstance>, array=0xd1c6b2c0 <s_SvcMessages>) at /tmp/bhl_build_1667961097/repo/src/game/client/engine_patches_linux.cpp:82
82      /tmp/bhl_build_1667961097/repo/src/game/client/engine_patches_linux.cpp: No such file or directory.

After bit of debuging I found that crash happens after restoring original mprotect flags, which traces further to LoadProtectFromProc.

Debug logs:

--> [f4800000-f4ad5000 r-xp 00000000 103:06 17986562                          /home/serfreeman1337/.local/share/Steam/steamapps/common/Half-Life/hw.so]
---> [-xp ]
-----> -
-----> x
-----> p
----->  
!!! start: 4102029312, flags: 4
--> [f4ad5000-f4ae0000 rw-p 002d4000 103:06 17986562                          /home/serfreeman1337/.local/share/Steam/steamapps/common/Half-Life/hw.so]
---> [w-p ]
-----> w
-----> -
-----> p
----->  
!!! start: 4104998912, flags: 2

I was able to solve my issue by chaning this line: https://github.com/tmp64/BugfixedHL-Rebased/blob/4b11feda78272ca9ccc58d4bdc4201973d41b10d/src/game/client/engine_patches_linux.cpp#L309 to:

- std::string protectStr = line.substr(19, 4);
+ std::string protectStr = line.substr(18, 4);

I think correct solution would be to find position of first space in line instead of hardcoding it.