commit 2c9f595
Sergio Durigan Junior
·
2026-03-27 14:08:33 +0000 UTC
parent 9a1b781
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>
1 files changed,
+9,
-4
M
snac.c
M
snac.c
+9,
-4
1@@ -182,8 +182,9 @@ int check_password(const char *uid, const char *passwd, const char *hash)
2 char* findprog(const char *prog)
3 /* find a prog in PATH and return the first match */
4 {
5- char *path_env, *path, *dir, filename[PATH_MAX];
6+ char *path_env, *path, *dir, *filename;
7 int len;
8+ size_t filename_sz;
9 struct stat sbuf;
10
11 path_env = getenv("PATH");
12@@ -195,6 +196,9 @@ char* findprog(const char *prog)
13 return NULL;
14 path = path_env;
15
16+ filename_sz = strlen(path) + strlen(prog) + 2;
17+ filename = xs_realloc(NULL, filename_sz);
18+
19 while ((dir = strsep(&path, ":")) != NULL) {
20 /* empty entries as ./ instead of / */
21 if (*dir == '\0')
22@@ -205,16 +209,17 @@ char* findprog(const char *prog)
23 while (len > 0 && dir[len-1] == '/')
24 dir[--len] = '\0';
25
26- len = snprintf(filename, sizeof(filename), "%s/%s", dir, prog);
27- if (len > 0 && len < (int) sizeof(filename) &&
28+ len = snprintf(filename, filename_sz, "%s/%s", dir, prog);
29+ if (len > 0 && len < (int) filename_sz &&
30 (stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&
31 access(filename, X_OK) == 0) {
32 free(path_env);
33- return strdup(filename);
34+ return filename;
35 }
36 }
37
38 free(path_env);
39+ xs_free(filename);
40 return NULL;
41 }
42