From: Paul Eggert Date: Tue, 17 Sep 2024 23:38:53 +0000 (-0700) Subject: Fix some #! misparsing in check_interpreter X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=515995b783c97a408201b3e2c7aaee2e9c2488f2;p=emacs.git Fix some #! misparsing in check_interpreter * 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) --- 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;