From 515995b783c97a408201b3e2c7aaee2e9c2488f2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 17 Sep 2024 16:38:53 -0700 Subject: [PATCH] Fix some #! misparsing in check_interpreter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * exec/exec.c: Do not include ctype.h, as the kernel does not care about the locale. (check_interpreter): Treat only spaces and tabs as white space. Do not inspect more bytes than were read. Although the resulting code does not exactly match what the Android kernel does, it’s closer than what it was before. (cherry picked from commit e0b027d1215ed32fe0f3d0956d2d7a81552274f2) --- exec/exec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exec/exec.c b/exec/exec.c index 775a8b06b96..f31c9a89744 100644 --- a/exec/exec.c +++ b/exec/exec.c @@ -24,7 +24,6 @@ along with GNU Emacs. If not, see . */ #include #include #include -#include #include #include @@ -116,11 +115,11 @@ check_interpreter (const char *name, int fd, const char **extra) /* Strip leading whitespace. */ start = buffer; - while (*start && ((unsigned char) *start) < 128 && isspace (*start)) + while (start < buffer + rc && (*start == ' ' || *start == '\t')) ++start; /* Look for a newline character. */ - end = memchr (start, '\n', rc); + end = memchr (start, '\n', buffer + rc - start); if (!end) goto fail; @@ -130,11 +129,12 @@ check_interpreter (const char *name, int fd, const char **extra) *end = '\0'; /* Now look for any whitespace characters. */ - ws = strchr (start, ' '); + for (ws = start; *ws && *ws != ' ' && *ws != '\t'; ws++) + continue; /* If there's no whitespace, return the entire start. */ - if (!ws) + if (!*ws) { if (lseek (fd, 0, SEEK_SET)) goto fail; -- 2.39.5