From c2c84e4bd8ea9e258c94d194db0f4e311d3a757f Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 27 Jan 2025 16:48:11 -0800 Subject: [PATCH] FEXLoader/ELFCodeLoader: Be robust against zero length environment variables For some reason steamwebhelper is setting a zero length environment variable. This was causing an assert to be raised early as the web helper was starting up. Just stop trying to memcpy the zero length string, gets steamwebhelper working in the steam beta client again --- Source/Tools/FEXLoader/ELFCodeLoader.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Tools/FEXLoader/ELFCodeLoader.h b/Source/Tools/FEXLoader/ELFCodeLoader.h index 733be0317f..99a782c547 100644 --- a/Source/Tools/FEXLoader/ELFCodeLoader.h +++ b/Source/Tools/FEXLoader/ELFCodeLoader.h @@ -655,7 +655,7 @@ class ELFCodeLoader final : public FEX::CodeLoader { } // Set the null terminator for the string - *reinterpret_cast(ArgumentBackingBase + CurrentOffset + ArgSize + 1) = 0; + *reinterpret_cast(ArgumentBackingBase + CurrentOffset + ArgSize) = 0; CurrentOffset += ArgSize + 1; } @@ -667,10 +667,12 @@ class ELFCodeLoader final : public FEX::CodeLoader { EnvpPointers[i] = EnvpBackingBaseGuest + CurrentOffset; // Copy the string in to the final location - memcpy(reinterpret_cast(EnvpBackingBase + CurrentOffset), &EnvironmentVariables[i].at(0), EnvpSize); + if (EnvpSize) { + memcpy(reinterpret_cast(EnvpBackingBase + CurrentOffset), &EnvironmentVariables[i].at(0), EnvpSize); + } // Set the null terminator for the string - *reinterpret_cast(EnvpBackingBase + CurrentOffset + EnvpSize + 1) = 0; + *reinterpret_cast(EnvpBackingBase + CurrentOffset + EnvpSize) = 0; CurrentOffset += EnvpSize + 1; }