diff options
| author | Paul Eggert | 2024-09-17 16:38:53 -0700 |
|---|---|---|
| committer | Paul Eggert | 2024-09-17 16:39:25 -0700 |
| commit | e0b027d1215ed32fe0f3d0956d2d7a81552274f2 (patch) | |
| tree | b673710118f654514a5d7e257fb77b97062acbf0 /exec | |
| parent | 58a44b6ac317c9a17bcdd208e4ec33ff9772429e (diff) | |
| download | emacs-e0b027d1215ed32fe0f3d0956d2d7a81552274f2.tar.gz emacs-e0b027d1215ed32fe0f3d0956d2d7a81552274f2.zip | |
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.
Diffstat (limited to 'exec')
| -rw-r--r-- | exec/exec.c | 10 |
1 files 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 <https://www.gnu.org/licenses/>. */ | |||
| 24 | #include <fcntl.h> | 24 | #include <fcntl.h> |
| 25 | #include <assert.h> | 25 | #include <assert.h> |
| 26 | #include <string.h> | 26 | #include <string.h> |
| 27 | #include <ctype.h> | ||
| 28 | #include <stdlib.h> | 27 | #include <stdlib.h> |
| 29 | 28 | ||
| 30 | #include <sys/ptrace.h> | 29 | #include <sys/ptrace.h> |
| @@ -116,11 +115,11 @@ check_interpreter (const char *name, int fd, const char **extra) | |||
| 116 | 115 | ||
| 117 | /* Strip leading whitespace. */ | 116 | /* Strip leading whitespace. */ |
| 118 | start = buffer; | 117 | start = buffer; |
| 119 | while (*start && ((unsigned char) *start) < 128 && isspace (*start)) | 118 | while (start < buffer + rc && (*start == ' ' || *start == '\t')) |
| 120 | ++start; | 119 | ++start; |
| 121 | 120 | ||
| 122 | /* Look for a newline character. */ | 121 | /* Look for a newline character. */ |
| 123 | end = memchr (start, '\n', rc); | 122 | end = memchr (start, '\n', buffer + rc - start); |
| 124 | 123 | ||
| 125 | if (!end) | 124 | if (!end) |
| 126 | goto fail; | 125 | goto fail; |
| @@ -130,11 +129,12 @@ check_interpreter (const char *name, int fd, const char **extra) | |||
| 130 | *end = '\0'; | 129 | *end = '\0'; |
| 131 | 130 | ||
| 132 | /* Now look for any whitespace characters. */ | 131 | /* Now look for any whitespace characters. */ |
| 133 | ws = strchr (start, ' '); | 132 | for (ws = start; *ws && *ws != ' ' && *ws != '\t'; ws++) |
| 133 | continue; | ||
| 134 | 134 | ||
| 135 | /* If there's no whitespace, return the entire start. */ | 135 | /* If there's no whitespace, return the entire start. */ |
| 136 | 136 | ||
| 137 | if (!ws) | 137 | if (!*ws) |
| 138 | { | 138 | { |
| 139 | if (lseek (fd, 0, SEEK_SET)) | 139 | if (lseek (fd, 0, SEEK_SET)) |
| 140 | goto fail; | 140 | goto fail; |