stdenv: Improve ELF detection for isELF

The isELF function only checks whether ELF is contained within the first
4 bytes of the file, which is a bit fuzzy and will also return
successful if it's a text file starting with ELF, for example:

  ELF headers
  -----------

  Some text here about ELF headers...

So instead, we're now doing a precise match on \x7fELF.

Signed-off-by: aszlig <aszlig@nix.build>
Acked-by: @Ericson2314
Closes: https://github.com/NixOS/nixpkgs/pull/47244
This commit is contained in:
aszlig 2018-09-23 20:32:19 +02:00
parent 2b4b7d4ef3
commit b25b6e0c75
No known key found for this signature in database
GPG key ID: 684089CE67EBB691

View file

@ -211,7 +211,7 @@ isELF() {
exec {fd}< "$fn"
read -r -n 4 -u "$fd" magic
exec {fd}<&-
if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi
if [ "$magic" = $'\177ELF' ]; then return 0; else return 1; fi
}
# Return success if the specified file is a script (i.e. starts with