From owner-freebsd-audit Thu Mar 1 18: 6:35 2001 Delivered-To: freebsd-audit@freebsd.org Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by hub.freebsd.org (Postfix) with ESMTP id 9825A37B718 for ; Thu, 1 Mar 2001 18:06:22 -0800 (PST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.11.1/8.11.1) with ESMTP id f2226Md53114 for ; Thu, 1 Mar 2001 19:06:22 -0700 (MST) (envelope-from imp@harmony.village.org) Message-Id: <200103020206.f2226Md53114@harmony.village.org> To: audit@freebsd.org Subject: PATH_MAX vs MAXPATHLEN Date: Thu, 01 Mar 2001 19:06:21 -0700 From: Warner Losh Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 /* for MAXPATHLEN */ +#include #include -#if defined(sun) || defined(__NetBSD__) -# include -#endif +#include #include #include #include @@ -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 #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 +#include #include #include #include @@ -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 #include #include +#include +#include #include #include #include @@ -66,7 +68,6 @@ #include #include #include -#include #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 +#include #include #include #include @@ -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