From 2c9f5956b5ad435bff157182210c5fd9560f1e95 Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Fri, 27 Mar 2026 10:08:33 -0400 Subject: Drop PATH_MAX usage Strict POSIX systems (such as GNU Hurd) don't define PATH_MAX, which results in a build failure: https://buildd.debian.org/status/fetch.php?pkg=snac2&arch=hurd-amd64&ver=2.91-1&stamp=1774482136&raw=0 This commit replaces PATH_MAX with a dynamically-allocated buffer, which is the usual way of fixing these failures. Signed-off-by: Sergio Durigan Junior --- snac.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/snac.c b/snac.c index 9c84205..f461280 100644 --- a/snac.c +++ b/snac.c @@ -182,8 +182,9 @@ int check_password(const char *uid, const char *passwd, const char *hash) char* findprog(const char *prog) /* find a prog in PATH and return the first match */ { - char *path_env, *path, *dir, filename[PATH_MAX]; + char *path_env, *path, *dir, *filename; int len; + size_t filename_sz; struct stat sbuf; path_env = getenv("PATH"); @@ -195,6 +196,9 @@ char* findprog(const char *prog) return NULL; path = path_env; + filename_sz = strlen(path) + strlen(prog) + 2; + filename = xs_realloc(NULL, filename_sz); + while ((dir = strsep(&path, ":")) != NULL) { /* empty entries as ./ instead of / */ if (*dir == '\0') @@ -205,16 +209,17 @@ char* findprog(const char *prog) while (len > 0 && dir[len-1] == '/') dir[--len] = '\0'; - len = snprintf(filename, sizeof(filename), "%s/%s", dir, prog); - if (len > 0 && len < (int) sizeof(filename) && + len = snprintf(filename, filename_sz, "%s/%s", dir, prog); + if (len > 0 && len < (int) filename_sz && (stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) && access(filename, X_OK) == 0) { free(path_env); - return strdup(filename); + return filename; } } free(path_env); + xs_free(filename); return NULL; } -- cgit