Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSAN reexec of shebang script results in unexpected argv[] #102579

Open
awelzel opened this issue Aug 9, 2024 · 0 comments
Open

TSAN reexec of shebang script results in unexpected argv[] #102579

awelzel opened this issue Aug 9, 2024 · 0 comments
Labels
compiler-rt:tsan Thread sanitizer

Comments

@awelzel
Copy link

awelzel commented Aug 9, 2024

We've run into spurious testing failures when running a TSAN instrumented executable as script interpreter in a shebang:
zeek/zeek#3774

This was tracked down to TSAN deciding to reexecute and then the shebang arguments are duplicated in argv[].

Here's a short reproducer, notice the -b -- and ./main.sh entries duplicated after a reexec is forced with ulimit -s unlimited. For us it was a spurious failure because the reexec wasn't deterministic.

$ cat main.c
#include <stdio.h>

int main(int argc, const char *argv[]) {
  printf("argc=%d\n", argc);
  for ( int i = 0; i < argc; i++) {
    printf("argv[%d]=%s\n", i, argv[i]);
  }
}

$ cat main.sh 
#!./main -b --

$ clang-18 -fsanitize=thread main.c -o main 

$ ./main.sh -a
argc=4
argv[0]=./main
argv[1]=-b --
argv[2]=./main.sh
argv[3]=-a

# force a tsan re-exec
$ ulimit -s unlimited

$ ./main.sh -a
argc=6
argv[0]=./main
argv[1]=-b --           # duplicate
argv[2]=./main.sh       # duplicate
argv[3]=-b --
argv[4]=./main.sh
argv[5]=-a
@EugeneZelenko EugeneZelenko added compiler-rt:tsan Thread sanitizer and removed new issue labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:tsan Thread sanitizer
Projects
None yet
Development

No branches or pull requests

2 participants