aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@sergiodj.net>2026-03-27 10:08:33 -0400
committerSergio Durigan Junior <sergiodj@sergiodj.net>2026-03-27 10:08:33 -0400
commit2c9f5956b5ad435bff157182210c5fd9560f1e95 (patch)
tree32c124ddd3f538947682baf12c9b3dbff24e0d67
parent9a1b78113e7fd728acd5cb6b58c24fb53f24f99a (diff)
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 <sergiodj@sergiodj.net>
-rw-r--r--snac.c13
1 files 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;
}