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

skip-if-exec-format-error doesn't work #116

Open
zackw opened this issue Dec 15, 2020 · 0 comments
Open

skip-if-exec-format-error doesn't work #116

zackw opened this issue Dec 15, 2020 · 0 comments
Labels
bug Confirmed to be a bug in libxcrypt. help wanted The libxcrypt core developers do not plan to work on this themselves but would review a PR. only-tests Issues that cause test failures but do not affect normal use of the library.

Comments

@zackw
Copy link
Collaborator

zackw commented Dec 15, 2020

I have discovered that skip-if-exec-format-error doesn't work reliably. Observe:

$ ./m4/skip-if-exec-format-error ./wrong-arch-true; echo $?
./m4/skip-if-exec-format-error:line 17: ./wrong-arch-true: cannot execute binary file: Exec format error
77

but

$ dd if=wrong-arch-true of=test.1 bs=6 count=1 status=none
$ chmod +x test.1
$ ./m4/skip-if-exec-format-error ./test.1; echo $?
./test.1: line 1: $'\177ELF\002\001': command not found
127

What on earth? Turns out that on most Unixes, the C library routine execvp will run /bin/sh argv... if the attempt to invoke argv[0] fails with ENOEXEC. If there are NULs in the first few dozen bytes of the file, /bin/sh will generate the "Exec format error" message, but if they're aren't, it'll try to run the sucker as a shell script.

There isn't, AFAICT, a good way to prevent this behavior, short of reimplementing execvp by hand in C, which wouldn't be that bad except that, when cross-compiling (which is the only time skip-if-exec-format-error gets used) we'd need a C compiler for the build machine as well as the host. I'm arguing with myself about whether it's worth the hassle.

@zackw zackw self-assigned this Mar 26, 2024
@zackw zackw added bug Confirmed to be a bug in libxcrypt. help wanted The libxcrypt core developers do not plan to work on this themselves but would review a PR. only-tests Issues that cause test failures but do not affect normal use of the library. labels Mar 26, 2024
@zackw zackw removed their assignment Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed to be a bug in libxcrypt. help wanted The libxcrypt core developers do not plan to work on this themselves but would review a PR. only-tests Issues that cause test failures but do not affect normal use of the library.
Projects
None yet
Development

No branches or pull requests

1 participant