Skip to content

Commit a62e164

Browse files
39958: Add extra byte to PATH_MAX allocations.
This ensures we've got enough space for a null, although this isn't always needed.
1 parent 297471c commit a62e164

File tree

8 files changed

+28
-22
lines changed

8 files changed

+28
-22
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2016-11-17 Peter Stephenson <p.w.stephenson@ntlworld.com>
2+
3+
* 39958: Src/Zle/compctl.c, Src/builtin.c, Src/compat.c,
4+
Src/exec.c, Src/glob.c, Src/hist.c, Src/utils.c: Add spare byte
5+
to PATH_MAX allocation to allow for possible null.
6+
17
2016-11-17 Daniel Shahaf <d.s@daniel.shahaf.name>
28

39
* 39921: Completion/Unix/Command/_git: __git_recent_branches:

Src/Zle/compctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ gen_matches_files(int dirs, int execs, int all)
21352135
{
21362136
DIR *d;
21372137
struct stat buf;
2138-
char *n, p[PATH_MAX], *q = NULL, *e, *pathpref;
2138+
char *n, p[PATH_MAX+1], *q = NULL, *e, *pathpref;
21392139
LinkList l = NULL;
21402140
int ns = 0, ng = opts[NULLGLOB], test, aw = addwhat, pathpreflen;
21412141

Src/builtin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ cd_do_chdir(char *cnam, char *dest, int hard)
973973
* Normalize path under Cygwin to avoid messing with
974974
* DOS style names with drives in them
975975
*/
976-
static char buf[PATH_MAX];
976+
static char buf[PATH_MAX+1];
977977
#ifdef HAVE_CYGWIN_CONV_PATH
978978
cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, dest, buf,
979979
PATH_MAX);

Src/compat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ zgetdir(struct dirsav *d)
270270
int len;
271271
#endif
272272

273-
buf = zhalloc(bufsiz = PATH_MAX);
273+
buf = zhalloc(bufsiz = PATH_MAX+1);
274274
pos = bufsiz - 1;
275275
buf[pos] = '\0';
276276
strcpy(nbuf, "../");
@@ -439,11 +439,11 @@ zgetcwd(void)
439439
free(cwd);
440440
}
441441
#else
442-
char *cwdbuf = zalloc(PATH_MAX);
442+
char *cwdbuf = zalloc(PATH_MAX+1);
443443
ret = getcwd(cwdbuf, PATH_MAX);
444444
if (ret)
445445
ret = dupstring(ret);
446-
zfree(cwdbuf, PATH_MAX);
446+
zfree(cwdbuf, PATH_MAX+1);
447447
#endif /* GETCWD_CALLS_MALLOC */
448448
}
449449
#endif /* HAVE_GETCWD */

Src/exec.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static int
437437
zexecve(char *pth, char **argv, char **newenvp)
438438
{
439439
int eno;
440-
static char buf[PATH_MAX * 2];
440+
static char buf[PATH_MAX * 2+1];
441441
char **eep;
442442

443443
unmetafy(pth, NULL);
@@ -620,7 +620,7 @@ static void
620620
execute(LinkList args, int flags, int defpath)
621621
{
622622
Cmdnam cn;
623-
char buf[MAXCMDLEN], buf2[MAXCMDLEN];
623+
char buf[MAXCMDLEN+1], buf2[MAXCMDLEN+1];
624624
char *s, *z, *arg0;
625625
char **argv, **pp, **newenvp = NULL;
626626
int eno = 0, ee;
@@ -701,7 +701,7 @@ execute(LinkList args, int flags, int defpath)
701701

702702
/* for command -p, search the default path */
703703
if (defpath) {
704-
char pbuf[PATH_MAX];
704+
char pbuf[PATH_MAX+1];
705705
char *dptr;
706706

707707
if (!search_defpath(arg0, pbuf, PATH_MAX)) {
@@ -721,7 +721,7 @@ execute(LinkList args, int flags, int defpath)
721721
} else {
722722

723723
if ((cn = (Cmdnam) cmdnamtab->getnode(cmdnamtab, arg0))) {
724-
char nn[PATH_MAX], *dptr;
724+
char nn[PATH_MAX+1], *dptr;
725725

726726
if (cn->node.flags & HASHED)
727727
strcpy(nn, cn->u.cmd);
@@ -814,7 +814,7 @@ findcmd(char *arg0, int docopy, int default_path)
814814
}
815815
}
816816
if (cn) {
817-
char nn[PATH_MAX];
817+
char nn[PATH_MAX+1];
818818

819819
if (cn->node.flags & HASHED)
820820
strcpy(nn, cn->u.cmd);
@@ -905,7 +905,7 @@ mod_export Cmdnam
905905
hashcmd(char *arg0, char **pp)
906906
{
907907
Cmdnam cn;
908-
char *s, buf[PATH_MAX];
908+
char *s, buf[PATH_MAX+1];
909909
char **pq;
910910

911911
for (; *pp; pp++)
@@ -5602,7 +5602,7 @@ runshfunc(Eprog prog, FuncWrap wrap, char *name)
56025602
Eprog
56035603
getfpfunc(char *s, int *ksh, char **fname)
56045604
{
5605-
char **pp, buf[PATH_MAX];
5605+
char **pp, buf[PATH_MAX+1];
56065606
off_t len;
56075607
off_t rlen;
56085608
char *d;
@@ -5732,7 +5732,7 @@ cancd(char *s)
57325732
char *t;
57335733

57345734
if (*s != '/') {
5735-
char sbuf[PATH_MAX], **cp;
5735+
char sbuf[PATH_MAX+1], **cp;
57365736

57375737
if (cancd2(s))
57385738
return s;

Src/glob.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ addpath(char *s, int l)
283283
static int
284284
statfullpath(const char *s, struct stat *st, int l)
285285
{
286-
char buf[PATH_MAX];
286+
char buf[PATH_MAX+1];
287287

288288
DPUTS(strlen(s) + !*s + pathpos - pathbufcwd >= PATH_MAX,
289289
"BUG: statfullpath(): pathname too long");
@@ -779,7 +779,7 @@ parsepat(char *str)
779779

780780
/* Now there is no (#X) in front, we can check the path. */
781781
if (!pathbuf)
782-
pathbuf = zalloc(pathbufsz = PATH_MAX);
782+
pathbuf = zalloc(pathbufsz = PATH_MAX+1);
783783
DPUTS(pathbufcwd, "BUG: glob changed directory");
784784
if (*str == '/') { /* pattern has absolute path */
785785
str++;

Src/hist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ chrealpath(char **junkptr)
18431843
# ifdef REALPATH_ACCEPTS_NULL
18441844
char *lastpos, *nonreal, *real;
18451845
# else
1846-
char *lastpos, *nonreal, pathbuf[PATH_MAX];
1846+
char *lastpos, *nonreal, pathbuf[PATH_MAX+1];
18471847
char *real = pathbuf;
18481848
# endif
18491849
#endif

Src/utils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ ispwd(char *s)
845845
return 0;
846846
}
847847

848-
static char xbuf[PATH_MAX*2];
848+
static char xbuf[PATH_MAX*2+1];
849849

850850
/**/
851851
static char **
@@ -884,7 +884,7 @@ static int
884884
xsymlinks(char *s, int full)
885885
{
886886
char **pp, **opp;
887-
char xbuf2[PATH_MAX*3], xbuf3[PATH_MAX*2];
887+
char xbuf2[PATH_MAX*3+1], xbuf3[PATH_MAX*2+1];
888888
int t0, ret = 0;
889889
zulong xbuflen = strlen(xbuf);
890890

@@ -1003,7 +1003,7 @@ print_if_link(char *s, int all)
10031003
*xbuf = '\0';
10041004
if (all) {
10051005
char *start = s + 1;
1006-
char xbuflink[PATH_MAX];
1006+
char xbuflink[PATH_MAX+1];
10071007
for (;;) {
10081008
if (xsymlinks(start, 0) > 0) {
10091009
printf(" -> ");
@@ -1140,7 +1140,7 @@ finddir(char *s)
11401140
if(homenode.diff==1)
11411141
homenode.diff = 0;
11421142
if(!finddir_full)
1143-
finddir_full = zalloc(ffsz = PATH_MAX);
1143+
finddir_full = zalloc(ffsz = PATH_MAX+1);
11441144
finddir_full[0] = 0;
11451145
return finddir_last = NULL;
11461146
}
@@ -1644,7 +1644,7 @@ checkmailpath(char **s)
16441644
} else if (S_ISDIR(st.st_mode)) {
16451645
LinkList l;
16461646
DIR *lock = opendir(unmeta(*s));
1647-
char buf[PATH_MAX * 2], **arr, **ap;
1647+
char buf[PATH_MAX * 2 + 1], **arr, **ap;
16481648
int ct = 1;
16491649

16501650
if (lock) {
@@ -6916,7 +6916,7 @@ strsfx(char *s, char *t)
69166916
static int
69176917
upchdir(int n)
69186918
{
6919-
char buf[PATH_MAX];
6919+
char buf[PATH_MAX+1];
69206920
char *s;
69216921
int err = -1;
69226922

0 commit comments

Comments
 (0)