Skip to content

Commit

Permalink
FEXLoader/ELFCodeLoader: Be robust against zero length environment va…
Browse files Browse the repository at this point in the history
…riables

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
  • Loading branch information
Sonicadvance1 committed Jan 29, 2025
1 parent c2f8b5b commit c2c84e4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Source/Tools/FEXLoader/ELFCodeLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class ELFCodeLoader final : public FEX::CodeLoader {
}

// Set the null terminator for the string
*reinterpret_cast<uint8_t*>(ArgumentBackingBase + CurrentOffset + ArgSize + 1) = 0;
*reinterpret_cast<uint8_t*>(ArgumentBackingBase + CurrentOffset + ArgSize) = 0;

CurrentOffset += ArgSize + 1;
}
Expand All @@ -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<void*>(EnvpBackingBase + CurrentOffset), &EnvironmentVariables[i].at(0), EnvpSize);
if (EnvpSize) {
memcpy(reinterpret_cast<void*>(EnvpBackingBase + CurrentOffset), &EnvironmentVariables[i].at(0), EnvpSize);
}

// Set the null terminator for the string
*reinterpret_cast<uint8_t*>(EnvpBackingBase + CurrentOffset + EnvpSize + 1) = 0;
*reinterpret_cast<uint8_t*>(EnvpBackingBase + CurrentOffset + EnvpSize) = 0;

CurrentOffset += EnvpSize + 1;
}
Expand Down

0 comments on commit c2c84e4

Please sign in to comment.