1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-08-11 02:51:07 +02:00

39958: Add extra byte to PATH_MAX allocations.

This ensures we've got enough space for a null, although this
isn't always needed.
This commit is contained in:
Peter Stephenson 2016-11-17 19:49:17 +00:00
parent 297471cf77
commit a62e1640bc
8 changed files with 28 additions and 22 deletions

View file

@ -1,3 +1,9 @@
2016-11-17 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 39958: Src/Zle/compctl.c, Src/builtin.c, Src/compat.c,
Src/exec.c, Src/glob.c, Src/hist.c, Src/utils.c: Add spare byte
to PATH_MAX allocation to allow for possible null.
2016-11-17 Daniel Shahaf <d.s@daniel.shahaf.name> 2016-11-17 Daniel Shahaf <d.s@daniel.shahaf.name>
* 39921: Completion/Unix/Command/_git: __git_recent_branches: * 39921: Completion/Unix/Command/_git: __git_recent_branches:

View file

@ -2135,7 +2135,7 @@ gen_matches_files(int dirs, int execs, int all)
{ {
DIR *d; DIR *d;
struct stat buf; struct stat buf;
char *n, p[PATH_MAX], *q = NULL, *e, *pathpref; char *n, p[PATH_MAX+1], *q = NULL, *e, *pathpref;
LinkList l = NULL; LinkList l = NULL;
int ns = 0, ng = opts[NULLGLOB], test, aw = addwhat, pathpreflen; int ns = 0, ng = opts[NULLGLOB], test, aw = addwhat, pathpreflen;

View file

@ -973,7 +973,7 @@ cd_do_chdir(char *cnam, char *dest, int hard)
* Normalize path under Cygwin to avoid messing with * Normalize path under Cygwin to avoid messing with
* DOS style names with drives in them * DOS style names with drives in them
*/ */
static char buf[PATH_MAX]; static char buf[PATH_MAX+1];
#ifdef HAVE_CYGWIN_CONV_PATH #ifdef HAVE_CYGWIN_CONV_PATH
cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, dest, buf, cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, dest, buf,
PATH_MAX); PATH_MAX);

View file

@ -270,7 +270,7 @@ zgetdir(struct dirsav *d)
int len; int len;
#endif #endif
buf = zhalloc(bufsiz = PATH_MAX); buf = zhalloc(bufsiz = PATH_MAX+1);
pos = bufsiz - 1; pos = bufsiz - 1;
buf[pos] = '\0'; buf[pos] = '\0';
strcpy(nbuf, "../"); strcpy(nbuf, "../");
@ -439,11 +439,11 @@ zgetcwd(void)
free(cwd); free(cwd);
} }
#else #else
char *cwdbuf = zalloc(PATH_MAX); char *cwdbuf = zalloc(PATH_MAX+1);
ret = getcwd(cwdbuf, PATH_MAX); ret = getcwd(cwdbuf, PATH_MAX);
if (ret) if (ret)
ret = dupstring(ret); ret = dupstring(ret);
zfree(cwdbuf, PATH_MAX); zfree(cwdbuf, PATH_MAX+1);
#endif /* GETCWD_CALLS_MALLOC */ #endif /* GETCWD_CALLS_MALLOC */
} }
#endif /* HAVE_GETCWD */ #endif /* HAVE_GETCWD */

View file

@ -437,7 +437,7 @@ static int
zexecve(char *pth, char **argv, char **newenvp) zexecve(char *pth, char **argv, char **newenvp)
{ {
int eno; int eno;
static char buf[PATH_MAX * 2]; static char buf[PATH_MAX * 2+1];
char **eep; char **eep;
unmetafy(pth, NULL); unmetafy(pth, NULL);
@ -620,7 +620,7 @@ static void
execute(LinkList args, int flags, int defpath) execute(LinkList args, int flags, int defpath)
{ {
Cmdnam cn; Cmdnam cn;
char buf[MAXCMDLEN], buf2[MAXCMDLEN]; char buf[MAXCMDLEN+1], buf2[MAXCMDLEN+1];
char *s, *z, *arg0; char *s, *z, *arg0;
char **argv, **pp, **newenvp = NULL; char **argv, **pp, **newenvp = NULL;
int eno = 0, ee; int eno = 0, ee;
@ -701,7 +701,7 @@ execute(LinkList args, int flags, int defpath)
/* for command -p, search the default path */ /* for command -p, search the default path */
if (defpath) { if (defpath) {
char pbuf[PATH_MAX]; char pbuf[PATH_MAX+1];
char *dptr; char *dptr;
if (!search_defpath(arg0, pbuf, PATH_MAX)) { if (!search_defpath(arg0, pbuf, PATH_MAX)) {
@ -721,7 +721,7 @@ execute(LinkList args, int flags, int defpath)
} else { } else {
if ((cn = (Cmdnam) cmdnamtab->getnode(cmdnamtab, arg0))) { if ((cn = (Cmdnam) cmdnamtab->getnode(cmdnamtab, arg0))) {
char nn[PATH_MAX], *dptr; char nn[PATH_MAX+1], *dptr;
if (cn->node.flags & HASHED) if (cn->node.flags & HASHED)
strcpy(nn, cn->u.cmd); strcpy(nn, cn->u.cmd);
@ -814,7 +814,7 @@ findcmd(char *arg0, int docopy, int default_path)
} }
} }
if (cn) { if (cn) {
char nn[PATH_MAX]; char nn[PATH_MAX+1];
if (cn->node.flags & HASHED) if (cn->node.flags & HASHED)
strcpy(nn, cn->u.cmd); strcpy(nn, cn->u.cmd);
@ -905,7 +905,7 @@ mod_export Cmdnam
hashcmd(char *arg0, char **pp) hashcmd(char *arg0, char **pp)
{ {
Cmdnam cn; Cmdnam cn;
char *s, buf[PATH_MAX]; char *s, buf[PATH_MAX+1];
char **pq; char **pq;
for (; *pp; pp++) for (; *pp; pp++)
@ -5602,7 +5602,7 @@ runshfunc(Eprog prog, FuncWrap wrap, char *name)
Eprog Eprog
getfpfunc(char *s, int *ksh, char **fname) getfpfunc(char *s, int *ksh, char **fname)
{ {
char **pp, buf[PATH_MAX]; char **pp, buf[PATH_MAX+1];
off_t len; off_t len;
off_t rlen; off_t rlen;
char *d; char *d;
@ -5732,7 +5732,7 @@ cancd(char *s)
char *t; char *t;
if (*s != '/') { if (*s != '/') {
char sbuf[PATH_MAX], **cp; char sbuf[PATH_MAX+1], **cp;
if (cancd2(s)) if (cancd2(s))
return s; return s;

View file

@ -283,7 +283,7 @@ addpath(char *s, int l)
static int static int
statfullpath(const char *s, struct stat *st, int l) statfullpath(const char *s, struct stat *st, int l)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX+1];
DPUTS(strlen(s) + !*s + pathpos - pathbufcwd >= PATH_MAX, DPUTS(strlen(s) + !*s + pathpos - pathbufcwd >= PATH_MAX,
"BUG: statfullpath(): pathname too long"); "BUG: statfullpath(): pathname too long");
@ -779,7 +779,7 @@ parsepat(char *str)
/* Now there is no (#X) in front, we can check the path. */ /* Now there is no (#X) in front, we can check the path. */
if (!pathbuf) if (!pathbuf)
pathbuf = zalloc(pathbufsz = PATH_MAX); pathbuf = zalloc(pathbufsz = PATH_MAX+1);
DPUTS(pathbufcwd, "BUG: glob changed directory"); DPUTS(pathbufcwd, "BUG: glob changed directory");
if (*str == '/') { /* pattern has absolute path */ if (*str == '/') { /* pattern has absolute path */
str++; str++;

View file

@ -1843,7 +1843,7 @@ chrealpath(char **junkptr)
# ifdef REALPATH_ACCEPTS_NULL # ifdef REALPATH_ACCEPTS_NULL
char *lastpos, *nonreal, *real; char *lastpos, *nonreal, *real;
# else # else
char *lastpos, *nonreal, pathbuf[PATH_MAX]; char *lastpos, *nonreal, pathbuf[PATH_MAX+1];
char *real = pathbuf; char *real = pathbuf;
# endif # endif
#endif #endif

View file

@ -845,7 +845,7 @@ ispwd(char *s)
return 0; return 0;
} }
static char xbuf[PATH_MAX*2]; static char xbuf[PATH_MAX*2+1];
/**/ /**/
static char ** static char **
@ -884,7 +884,7 @@ static int
xsymlinks(char *s, int full) xsymlinks(char *s, int full)
{ {
char **pp, **opp; char **pp, **opp;
char xbuf2[PATH_MAX*3], xbuf3[PATH_MAX*2]; char xbuf2[PATH_MAX*3+1], xbuf3[PATH_MAX*2+1];
int t0, ret = 0; int t0, ret = 0;
zulong xbuflen = strlen(xbuf); zulong xbuflen = strlen(xbuf);
@ -1003,7 +1003,7 @@ print_if_link(char *s, int all)
*xbuf = '\0'; *xbuf = '\0';
if (all) { if (all) {
char *start = s + 1; char *start = s + 1;
char xbuflink[PATH_MAX]; char xbuflink[PATH_MAX+1];
for (;;) { for (;;) {
if (xsymlinks(start, 0) > 0) { if (xsymlinks(start, 0) > 0) {
printf(" -> "); printf(" -> ");
@ -1140,7 +1140,7 @@ finddir(char *s)
if(homenode.diff==1) if(homenode.diff==1)
homenode.diff = 0; homenode.diff = 0;
if(!finddir_full) if(!finddir_full)
finddir_full = zalloc(ffsz = PATH_MAX); finddir_full = zalloc(ffsz = PATH_MAX+1);
finddir_full[0] = 0; finddir_full[0] = 0;
return finddir_last = NULL; return finddir_last = NULL;
} }
@ -1644,7 +1644,7 @@ checkmailpath(char **s)
} else if (S_ISDIR(st.st_mode)) { } else if (S_ISDIR(st.st_mode)) {
LinkList l; LinkList l;
DIR *lock = opendir(unmeta(*s)); DIR *lock = opendir(unmeta(*s));
char buf[PATH_MAX * 2], **arr, **ap; char buf[PATH_MAX * 2 + 1], **arr, **ap;
int ct = 1; int ct = 1;
if (lock) { if (lock) {
@ -6916,7 +6916,7 @@ strsfx(char *s, char *t)
static int static int
upchdir(int n) upchdir(int n)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX+1];
char *s; char *s;
int err = -1; int err = -1;