Date: Thu, 01 Mar 2001 19:06:21 -0700 From: Warner Losh <imp@harmony.village.org> To: audit@freebsd.org Subject: PATH_MAX vs MAXPATHLEN Message-ID: <200103020206.f2226Md53114@harmony.village.org>
next in thread | raw e-mail | index | archive | help
Here's a patch that changes MAXPATHLEN to PATH_MAX in src/bin. Plus fixes disordering of one include file. I believe that these changes are correct, but wanted another set of eyes on them. Comments? Warner Index: cp/cp.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/cp/cp.c,v retrieving revision 1.24 diff -u -r1.24 cp.c --- cp/cp.c 1999/11/28 09:34:21 1.24 +++ cp/cp.c 2001/03/02 02:01:16 @@ -69,6 +69,7 @@ #include <err.h> #include <errno.h> #include <fts.h> +#include <limits.h> #include <stdio.h> #include <string.h> #include <unistd.h> @@ -177,7 +178,7 @@ /* Save the target base in "to". */ target = argv[--argc]; - if (strlen(target) > MAXPATHLEN) + if (strlen(target) > PATH_MAX) errx(1, "%s: name too long", target); (void)strcpy(to.p_path, target); to.p_end = to.p_path + strlen(to.p_path); @@ -318,7 +319,7 @@ if (*p != '/' && target_mid[-1] != '/') *target_mid++ = '/'; *target_mid = 0; - if (target_mid - to.p_path + nlen > MAXPATHLEN) { + if (target_mid - to.p_path + nlen > PATH_MAX) { warnx("%s%s: name too long (not copied)", to.p_path, p); badcp = rval = 1; Index: cp/extern.h =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/cp/extern.h,v retrieving revision 1.9 diff -u -r1.9 extern.h --- cp/extern.h 1999/08/27 23:13:39 1.9 +++ cp/extern.h 2001/03/02 01:55:20 @@ -37,7 +37,7 @@ typedef struct { char *p_end; /* pointer to NULL at end of path */ char *target_end; /* pointer to end of target base */ - char p_path[MAXPATHLEN + 1]; /* pointer to the start of a path */ + char p_path[PATH_MAX]; /* pointer to the start of a path */ } PATH_T; extern PATH_T to; Index: cp/utils.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/cp/utils.c,v retrieving revision 1.28 diff -u -r1.28 utils.c --- cp/utils.c 2000/10/10 01:48:18 1.28 +++ cp/utils.c 2001/03/02 02:01:31 @@ -50,6 +50,7 @@ #include <errno.h> #include <fcntl.h> #include <fts.h> +#include <limits.h> #include <stdio.h> #include <sysexits.h> #include <unistd.h> @@ -209,7 +210,7 @@ int exists; { int len; - char link[MAXPATHLEN]; + char link[PATH_MAX]; if ((len = readlink(p->fts_path, link, sizeof(link) - 1)) == -1) { warn("readlink: %s", p->fts_path); Index: ed/ed.h =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/ed/ed.h,v retrieving revision 1.13 diff -u -r1.13 ed.h --- ed/ed.h 1999/08/27 23:14:13 1.13 +++ ed/ed.h 2001/03/02 02:02:11 @@ -28,11 +28,9 @@ * $FreeBSD: src/bin/ed/ed.h,v 1.13 1999/08/27 23:14:13 peter Exp $ */ -#include <sys/param.h> /* for MAXPATHLEN */ +#include <sys/param.h> #include <errno.h> -#if defined(sun) || defined(__NetBSD__) -# include <limits.h> -#endif +#include <limits.h> #include <regex.h> #include <signal.h> #include <stdio.h> @@ -43,10 +41,6 @@ #define ERR (-2) #define EMOD (-3) #define FATAL (-4) - -#ifndef MAXPATHLEN -# define MAXPATHLEN 255 /* _POSIX_PATH_MAX */ -#endif #define MINBUFSZ 512 /* minimum buffer size - must be > 0 */ #define SE_MAX 30 /* max subexpressions in a regular expression */ Index: ed/main.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/ed/main.c,v retrieving revision 1.17 diff -u -r1.17 main.c --- ed/main.c 2000/11/27 06:26:48 1.17 +++ ed/main.c 2001/03/02 01:57:44 @@ -96,7 +96,7 @@ int sigflags = 0; /* if set, signals received while mutex set */ int sigactive = 0; /* if set, signal handlers are enabled */ -char old_filename[MAXPATHLEN + 1] = ""; /* default filename */ +char old_filename[PATH_MAX] = ""; /* default filename */ long current_addr; /* current address in editor buffer */ long addr_last; /* last address in editor buffer */ int lineno; /* script line number */ @@ -950,7 +950,7 @@ return NULL; if (n) printf("%s\n", shcmd + 1); return shcmd; - } else if (n - 1 > MAXPATHLEN) { + } else if (n - 1 > PATH_MAX) { sprintf(errmsg, "filename too long"); return NULL; } @@ -961,7 +961,7 @@ return NULL; } #endif - REALLOC(file, filesz, MAXPATHLEN + 1, NULL); + REALLOC(file, filesz, PATH_MAX, NULL); for (n = 0; *ibufp != '\n';) file[n++] = *ibufp++; file[n] = '\0'; @@ -1338,7 +1338,7 @@ } -/* strip_escapes: return copy of escaped string of at most length MAXPATHLEN */ +/* strip_escapes: return copy of escaped string of at most length PATH_MAX */ char * strip_escapes(s) char *s; @@ -1348,7 +1348,7 @@ int i = 0; - REALLOC(file, filesz, MAXPATHLEN + 1, NULL); + REALLOC(file, filesz, PATH_MAX, NULL); while (i < filesz - 1 /* Worry about a possible trailing escape */ && (file[i++] = (*s == '\\') ? *++s : *s)) s++; @@ -1391,7 +1391,7 @@ sigflags &= ~(1 << (signo - 1)); if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 && (s = getenv("HOME")) != NULL && - (n = strlen(s)) + 8 <= MAXPATHLEN && /* "ed.hup" + '/' */ + (n = strlen(s)) + 8 <= PATH_MAX && /* "ed.hup" + '/' */ (hup = (char *) malloc(n + 10)) != NULL) { strcpy(hup, s); if (hup[n - 1] != '/') Index: ed/re.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/ed/re.c,v retrieving revision 1.15 diff -u -r1.15 re.c --- ed/re.c 1999/08/27 23:14:15 1.15 +++ ed/re.c 2001/03/02 01:57:53 @@ -40,7 +40,7 @@ extern int patlock; -char errmsg[MAXPATHLEN + 40] = ""; +char errmsg[PATH_MAX + 40] = ""; /* get_compiled_pattern: return pointer to compiled pattern from command buffer */ Index: ln/ln.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/ln/ln.c,v retrieving revision 1.18 diff -u -r1.18 ln.c --- ln/ln.c 2000/08/17 16:08:06 1.18 +++ ln/ln.c 2001/03/02 01:58:09 @@ -50,6 +50,7 @@ #include <err.h> #include <errno.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -145,7 +146,7 @@ { struct stat sb; int ch, exists, first; - char *p, path[MAXPATHLEN]; + char *p, path[PATH_MAX]; if (!sflag) { /* If target doesn't exist, quit now. */ Index: ls/print.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/ls/print.c,v retrieving revision 1.36 diff -u -r1.36 print.c --- ls/print.c 2000/07/04 23:09:23 1.36 +++ ls/print.c 2001/03/02 01:58:36 @@ -50,6 +50,7 @@ #include <errno.h> #include <fts.h> #include <grp.h> +#include <limits.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> @@ -495,7 +496,7 @@ FTSENT *p; { int lnklen; - char name[MAXPATHLEN + 1], path[MAXPATHLEN + 1]; + char name[PATH_MAX], path[PATH_MAX]; if (p->fts_level == FTS_ROOTLEVEL) (void)snprintf(name, sizeof(name), "%s", p->fts_name); Index: mv/mv.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/mv/mv.c,v retrieving revision 1.27 diff -u -r1.27 mv.c --- mv/mv.c 2000/07/20 18:30:00 1.27 +++ mv/mv.c 2001/03/02 02:02:56 @@ -57,6 +57,7 @@ #include <err.h> #include <errno.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -81,7 +82,7 @@ register char *p, *endp; struct stat sb; int ch; - char path[MAXPATHLEN]; + char path[PATH_MAX]; while ((ch = getopt(argc, argv, "fiv")) != -1) switch (ch) { @@ -136,7 +137,7 @@ while (p != *argv && p[-1] != '/') --p; - if ((baselen + (len = strlen(p))) >= MAXPATHLEN) { + if ((baselen + (len = strlen(p))) >= PATH_MAX) { warnx("%s: destination pathname too long", *argv); rval = 1; } else { @@ -200,7 +201,7 @@ if (errno == EXDEV) { struct statfs sfs; - char path[MAXPATHLEN]; + char path[PATH_MAX]; /* Can't mv(1) a mount point. */ if (realpath(from, path) == NULL) { Index: pax/pax.h =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/pax/pax.h,v retrieving revision 1.8 diff -u -r1.8 pax.h --- pax/pax.h 1999/08/27 23:14:45 1.8 +++ pax/pax.h 2001/03/02 01:59:15 @@ -50,7 +50,7 @@ #define DEVBLK 8192 /* default read blksize for devices */ #define FILEBLK 10240 /* default read blksize for files */ #define PAXPATHLEN 3072 /* maximum path length for pax. MUST be */ - /* longer than the system MAXPATHLEN */ + /* longer than the system PATH_MAX */ /* * Pax modes of operation Index: ps/ps.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/ps/ps.c,v retrieving revision 1.34 diff -u -r1.34 ps.c --- ps/ps.c 2001/01/24 12:59:50 1.34 +++ ps/ps.c 2001/03/02 01:59:21 @@ -229,7 +229,7 @@ /* FALLTHROUGH */ case 't': { struct stat sb; - char *ttypath, pathbuf[MAXPATHLEN]; + char *ttypath, pathbuf[PATH_MAX]; if (strcmp(optarg, "co") == 0) ttypath = _PATH_CONSOLE; Index: pwd/pwd.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/pwd/pwd.c,v retrieving revision 1.11 diff -u -r1.11 pwd.c --- pwd/pwd.c 2000/11/26 08:50:12 1.11 +++ pwd/pwd.c 2001/03/02 01:59:36 @@ -46,6 +46,7 @@ #endif /* not lint */ #include <err.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -60,7 +61,7 @@ { int ch; char *p; - char buf[MAXPATHLEN]; + char buf[PATH_MAX]; /* * Flags for pwd are a bit strange. The POSIX 1003.2B/D9 document Index: rcp/rcp.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/rcp/rcp.c,v retrieving revision 1.26 diff -u -r1.26 rcp.c --- rcp/rcp.c 2000/02/24 21:21:15 1.26 +++ rcp/rcp.c 2001/03/02 02:03:55 @@ -58,6 +58,8 @@ #include <err.h> #include <errno.h> #include <fcntl.h> +#include <libutil.h> +#include <limits.h> #include <netdb.h> #include <pwd.h> #include <signal.h> @@ -66,7 +68,6 @@ #include <string.h> #include <string.h> #include <unistd.h> -#include <libutil.h> #include "pathnames.h" #include "extern.h" @@ -513,7 +514,7 @@ { DIR *dirp; struct dirent *dp; - char *last, *vect[1], path[MAXPATHLEN]; + char *last, *vect[1], path[PATH_MAX]; if (!(dirp = opendir(name))) { run_err("%s: %s", name, strerror(errno)); @@ -546,7 +547,7 @@ continue; if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; - if (strlen(name) + 1 + strlen(dp->d_name) >= MAXPATHLEN - 1) { + if (strlen(name) + 1 + strlen(dp->d_name) >= PATH_MAX) { run_err("%s/%s: name too long", name, dp->d_name); continue; } Index: sh/histedit.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/bin/sh/histedit.c,v retrieving revision 1.14 diff -u -r1.14 histedit.c --- sh/histedit.c 2000/04/20 09:49:15 1.14 +++ sh/histedit.c 2001/03/02 02:00:45 @@ -43,6 +43,7 @@ #endif /* not lint */ #include <sys/param.h> +#include <limits.h> #include <paths.h> #include <stdio.h> #include <stdlib.h> @@ -179,7 +180,7 @@ static int active = 0; struct jmploc jmploc; struct jmploc *volatile savehandler; - char editfile[MAXPATHLEN + 1]; + char editfile[PATH_MAX]; FILE *efp; #ifdef __GNUC__ /* Avoid longjmp clobbering */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103020206.f2226Md53114>