From ceee0e795acad28b39e51256a7d10e568a49e2ce Mon Sep 17 00:00:00 2001 From: Oliver Nutter Date: Fri, 25 Apr 2025 09:02:27 -0500 Subject: [PATCH] Fix bounds check in which() --- unixlauncher.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/unixlauncher.c b/unixlauncher.c index 2b38683..d0c14c4 100644 --- a/unixlauncher.c +++ b/unixlauncher.c @@ -31,8 +31,7 @@ static char *which(const char *const executable) { dirs[dirs_length] = ':'; size_t dir_head = 0; - size_t i = 0; - do { + for (size_t i = 0; i <= dirs_length; i++) { if (dirs[i] == ':') { // Declare convenient path variables char *const dir = dirs + dir_head; @@ -59,7 +58,7 @@ static char *which(const char *const executable) { dir_head = i + 1; } - } while (dirs[i++]); + }; // Lookup has failed, free if necessary and return NULL if (exe_path != NULL) {