mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-02 08:42:48 +00:00
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.
This commit is contained in:
parent
99e8005137
commit
9842e24c34
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77407
10
bin/ed/ed.h
10
bin/ed/ed.h
@ -28,11 +28,9 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#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>
|
||||
@ -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
|
||||
|
@ -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] != '/')
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user