diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2023-02-03 16:12:30 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2023-02-04 12:11:32 +0100 |
commit | f83f6cd4dc21664721602ceb449631957e941215 (patch) | |
tree | 895104e30b0d111e439c52f40becc0e51e8b1196 | |
parent | e77a675e83ccbea65a50fe85dc9cb49fff5e0443 (diff) |
sfeed_gopher: remove PATH_MAX and restricting the path length
This make it also cleanly compile without any other changes on GNU/Hurd.
Reference: https://www.gnu.org/software/hurd/hurd/porting/guidelines.html
Section: "PATH_MAX, MAX_PATH, MAXPATHLEN, _POSIX_PATH_MAX"
The fopen() functions will return NULL when the path is too long and set
errno = ENAMETOOLONG.
"The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a
symbolic link produced an intermediate result with a length that exceeds
{PATH_MAX}."
Reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html
-rw-r--r-- | sfeed_gopher.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/sfeed_gopher.c b/sfeed_gopher.c index b4ce7d9..290d2d2 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -1,6 +1,5 @@ #include <sys/types.h> -#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -123,8 +122,8 @@ int main(int argc, char *argv[]) { FILE *fpitems, *fpindex, *fp; - char *name, *p, path[PATH_MAX + 1]; - int i, r; + char *name, *p; + int i; if (argc == 1) { if (pledge("stdio", NULL) == -1) @@ -168,15 +167,11 @@ main(int argc, char *argv[]) if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); - - r = snprintf(path, sizeof(path), "%s", name); - if (r < 0 || (size_t)r >= sizeof(path)) - errx(1, "path truncation: %s", path); - if (!(fpitems = fopen(path, "wb"))) + if (!(fpitems = fopen(name, "wb"))) err(1, "fopen"); printfeed(fpitems, fp, &f); checkfileerror(fp, argv[i], 'r'); - checkfileerror(fpitems, path, 'w'); + checkfileerror(fpitems, name, 'w'); fclose(fp); fclose(fpitems); @@ -185,7 +180,7 @@ main(int argc, char *argv[]) gophertext(fpindex, name); fprintf(fpindex, " (%lu/%lu)\t", f.totalnew, f.total); gophertext(fpindex, prefixpath); - gophertext(fpindex, path); + gophertext(fpindex, name); fprintf(fpindex, "\t%s\t%s\r\n", host, port); } fputs(".\r\n", fpindex); |