Skip to content

Commit

Permalink
Merge pull request FEX-Emu#4306 from Sonicadvance1/robust_zero_length…
Browse files Browse the repository at this point in the history
…_envp

FEXLoader/ELFCodeLoader: Be robust against zero length environment variables
  • Loading branch information
Sonicadvance1 authored Jan 29, 2025
2 parents c2f8b5b + c2c84e4 commit 2a4c169
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 2a4c169

Please sign in to comment.