From d33ad952085d6662fcbe7a8e6a71ec7374915c43 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 1 Jun 2004 01:22:27 +0000 Subject: [PATCH] Use PATH_MAX, not MAXPATHLEN since the former is standardized. --- CHANGES | 2 ++ alloc.c | 1 - check.c | 6 +++--- compat.h | 14 +++++++++++--- find_path.c | 4 ++-- getcwd.c | 2 +- parse.c | 4 ++-- sudo.c | 2 +- sudo.h | 3 ++- visudo.c | 2 +- 10 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index fe2a4ef53..0639f45e7 100644 --- a/CHANGES +++ b/CHANGES @@ -1695,3 +1695,5 @@ Sudo 1.6.7p5 released. 533) Fixed several issues when closing all open descriptors. Sudo now uses closefrom() if it exists. + +534) Use PATH_MAX, not MAXPATHLEN since the former is standardized. diff --git a/alloc.c b/alloc.c index 772194712..3db6e6de7 100644 --- a/alloc.c +++ b/alloc.c @@ -46,7 +46,6 @@ #else # include "emul/err.h" #endif /* HAVE_ERR_H */ -#include #include "sudo.h" diff --git a/check.c b/check.c index e450e4766..efa957189 100644 --- a/check.c +++ b/check.c @@ -316,7 +316,7 @@ build_timestamp(timestampdir, timestampfile) dirparent = def_timestampdir; len = easprintf(timestampdir, "%s/%s", dirparent, user_name); - if (len >= MAXPATHLEN) + if (len >= PATH_MAX) log_error(0, "timestamp path too long: %s", timestampdir); /* @@ -335,12 +335,12 @@ build_timestamp(timestampdir, timestampfile) p, *user_runas); else len = easprintf(timestampfile, "%s/%s/%s", dirparent, user_name, p); - if (len >= MAXPATHLEN) + if (len >= PATH_MAX) log_error(0, "timestamp path too long: %s", timestampfile); } else if (def_targetpw) { len = easprintf(timestampfile, "%s/%s/%s", dirparent, user_name, *user_runas); - if (len >= MAXPATHLEN) + if (len >= PATH_MAX) log_error(0, "timestamp path too long: %s", timestampfile); } else *timestampfile = NULL; diff --git a/compat.h b/compat.h index ce5c48c6d..381eafda6 100644 --- a/compat.h +++ b/compat.h @@ -37,10 +37,18 @@ #endif /* __P */ /* - * Some systems (ie ISC V/386) do not define MAXPATHLEN even in param.h + * Some systems do not define PATH_MAX. */ -#ifndef MAXPATHLEN -# define MAXPATHLEN 1024 +#ifndef PATH_MAX +# ifdef MAXPATHLEN +# define PATH_MAX MAXPATHLEN +# else +# ifdef _POSIX_PATH_MAX +# define PATH_MAX _POSIX_PATH_MAX +# else +# define PATH_MAX 1024 +# endif +# endif #endif /* diff --git a/find_path.c b/find_path.c index cbfb880e9..2ade456a1 100644 --- a/find_path.c +++ b/find_path.c @@ -67,14 +67,14 @@ find_path(infile, outfile, path) char **outfile; /* result parameter */ char *path; /* path to search */ { - static char command[MAXPATHLEN]; /* qualified filename */ + static char command[PATH_MAX]; /* qualified filename */ char *n; /* for traversing path */ char *origpath; /* so we can free path later */ char *result = NULL; /* result of path/file lookup */ int checkdot = 0; /* check current dir? */ int len; /* length parameter */ - if (strlen(infile) >= MAXPATHLEN) + if (strlen(infile) >= PATH_MAX) errx(1, "%s: File name too long", infile); /* diff --git a/getcwd.c b/getcwd.c index 2d9fe5121..e5c33b02b 100644 --- a/getcwd.c +++ b/getcwd.c @@ -131,7 +131,7 @@ getcwd(pt, size) */ if ((up = malloc(upsize = 1024 - 4)) == NULL) goto err; - eup = up + MAXPATHLEN; + eup = up + PATH_MAX; bup = up; up[0] = '.'; up[1] = '\0'; diff --git a/parse.c b/parse.c index 7a1d2321e..12f6835ca 100644 --- a/parse.c +++ b/parse.c @@ -238,7 +238,7 @@ command_matches(cmnd, cmnd_args, path, sudoers_args) struct stat pst; DIR *dirp; struct dirent *dent; - char buf[MAXPATHLEN]; + char buf[PATH_MAX]; static char *cmnd_base; /* Check for pseudo-commands */ @@ -350,7 +350,7 @@ command_matches(cmnd, cmnd_args, path, sudoers_args) return(FALSE); while ((dent = readdir(dirp)) != NULL) { - /* ignore paths > MAXPATHLEN (XXX - log) */ + /* ignore paths > PATH_MAX (XXX - log) */ if (strlcpy(buf, path, sizeof(buf)) >= sizeof(buf) || strlcat(buf, dent->d_name, sizeof(buf)) >= sizeof(buf)) continue; diff --git a/sudo.c b/sudo.c index a0169fbbb..abe3a2701 100644 --- a/sudo.c +++ b/sudo.c @@ -497,7 +497,7 @@ init_vars(sudo_mode) int nohostname, rval; /* Sanity check command from user. */ - if (user_cmnd == NULL && strlen(NewArgv[0]) >= MAXPATHLEN) + if (user_cmnd == NULL && strlen(NewArgv[0]) >= PATH_MAX) errx(1, "%s: File name too long", NewArgv[0]); #ifdef HAVE_TZSET diff --git a/sudo.h b/sudo.h index 7908f34cc..d458b4181 100644 --- a/sudo.h +++ b/sudo.h @@ -24,6 +24,7 @@ #define _SUDO_SUDO_H #include +#include #include "compat.h" #include "defaults.h" #include "logging.h" @@ -37,7 +38,7 @@ struct sudo_user { char *path; char *shell; char *tty; - char cwd[MAXPATHLEN]; + char cwd[PATH_MAX]; char *host; char *shost; char **runas; diff --git a/visudo.c b/visudo.c index 66cae343a..e0910dec7 100644 --- a/visudo.c +++ b/visudo.c @@ -119,7 +119,7 @@ main(argc, argv) int argc; char **argv; { - char buf[MAXPATHLEN*2]; /* buffer used for copying files */ + char buf[PATH_MAX*2]; /* buffer used for copying files */ char *Editor; /* editor to use */ char *UserEditor; /* editor user wants to use */ char *EditorPath; /* colon-separated list of editors */ -- 2.40.0