From b25b6e0c75867cd0ae9866b7a8f0d6e3a4be54d5 Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 23 Sep 2018 20:32:19 +0200 Subject: 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 Acked-by: @Ericson2314 Closes: https://github.com/NixOS/nixpkgs/pull/47244 --- pkgs/stdenv/generic/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 11d0f1fbce43..8af369b1d17d 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -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 -- cgit 1.4.1