From 6d5c9e2a159911e48f405cbdbd6eaeb8fb1aa421 Mon Sep 17 00:00:00 2001 From: imp Date: Tue, 29 May 2001 18:03:14 +0000 Subject: Use PATH_MAX rather than MAXPATHLEN. Also fix a possible off by one error caused by the -1 being on the wrong side of the comparison. This would not cause an overflow, as near as I can tell, because we truncate later anyway. We'd just fail to get a diagnostic for 1024 and 1025 byte file names. --- bin/ed/ed.h | 10 ++-------- bin/ed/main.c | 15 ++++++++------- bin/ed/re.c | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) (limited to 'bin/ed') diff --git a/bin/ed/ed.h b/bin/ed/ed.h index d313a84..34cd276 100644 --- a/bin/ed/ed.h +++ b/bin/ed/ed.h @@ -28,11 +28,9 @@ * $FreeBSD$ */ -#include /* for MAXPATHLEN */ +#include #include -#if defined(sun) || defined(__NetBSD__) -# include -#endif +#include #include #include #include @@ -44,10 +42,6 @@ #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 */ #ifdef INT_MAX diff --git a/bin/ed/main.c b/bin/ed/main.c index 2fef891..bb651e5 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -96,7 +96,7 @@ int scripted = 0; /* if set, suppress diagnostics */ 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 */ @@ -948,9 +948,10 @@ get_filename() ibufp++; if ((n = get_shell_command()) < 0) return NULL; - if (n) printf("%s\n", shcmd + 1); + if (n) + printf("%s\n", shcmd + 1); return shcmd; - } else if (n - 1 > MAXPATHLEN) { + } else if (n > PATH_MAX - 1) { sprintf(errmsg, "filename too long"); return NULL; } @@ -961,7 +962,7 @@ get_filename() 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 +1339,7 @@ has_trailing_escape(s, t) } -/* 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 +1349,7 @@ strip_escapes(s) 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 +1392,7 @@ handle_hup(signo) 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] != '/') diff --git a/bin/ed/re.c b/bin/ed/re.c index d81d0d7..523e2a4 100644 --- a/bin/ed/re.c +++ b/bin/ed/re.c @@ -40,7 +40,7 @@ static char * const rcsid = extern int patlock; -char errmsg[MAXPATHLEN + 40] = ""; +char errmsg[PATH_MAX + 40] = ""; /* get_compiled_pattern: return pointer to compiled pattern from command buffer */ -- cgit v1.1