Skip to content

Fix execl/execle/execlp varargs argument corruption#3582

Merged
ptitSeb merged 1 commit intoptitSeb:mainfrom
gigachadmma69:fix/execl-varargs
Feb 28, 2026
Merged

Fix execl/execle/execlp varargs argument corruption#3582
ptitSeb merged 1 commit intoptitSeb:mainfrom
gigachadmma69:fix/execl-varargs

Conversation

@gigachadmma69
Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where my_execl(), my_execle(), and my_execlp() always read the last vararg instead of each argument in sequence.

The argument-filling loop used getVargN(emu, cnt+1) (constant index — always the last arg before NULL) instead of getVargN(emu, i+1) (incrementing index — each arg in order). This corrupted the argv array passed to execv/execve/execvp.

Before (broken):

for(int i=0; i<cnt; ++i)
    argv[i] = getVargN(emu, cnt+1);  // always reads last arg

After (fixed):

for(int i=0; i<cnt; ++i)
    argv[i] = getVargN(emu, i+1);    // reads each arg in order

For example, execl("./game", "-fullscreen", "-nosound", NULL) would produce argv = [NULL, NULL] (reading past the args) instead of argv = ["-fullscreen", "-nosound"].

Fixes #3542

Test plan

  • Compile on ARM64
  • Test with an x64 binary that calls execl() to re-exec itself

🤖 Generated with Claude Code

The argument-filling loop in my_execl(), my_execle(), and my_execlp()
used getVargN(emu, cnt+1) which always reads the last vararg before
NULL. This meant every argv entry was filled with the same (wrong)
value, corrupting the argument list passed to execv/execve/execvp.

Fix by using getVargN(emu, i+1) to read each argument in order.

This caused x64 applications that use execl() to re-exec themselves
(e.g. game restart via fork+execl) to fail with missing binary path.

Fixes ptitSeb#3542

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ptitSeb ptitSeb merged commit b5639f8 into ptitSeb:main Feb 28, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

execl() does not pass binary path when re-execing x64 binaries; post-fork child hangs in multi-threaded game

2 participants