Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
amoldeshpande committed Aug 22, 2020
2 parents 02214de + 7d25c5d commit 7c3ca17
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ tcsh
tcsh-*.tar.gz
tests/package.m4
tests/testsuite
testsuite.dir/**
testsuite.log
*.suo
*~
.vs/
64 changes: 56 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,68 @@ branches:
only:
- master
- coverity_scan

language: c

arch:
- amd64
- arm64
- ppc64le
- s390x

compiler:
- gcc
- clang

os:
- linux
- freebsd
- osx

jobs:
exclude:
- os: osx
compiler: gcc
include:
- name: 'Linux 32-bit gcc'
arch: amd64
compiler: gcc
os: linux
env: CFLAGS=-m32
addons:
apt:
packages:
- gcc-multilib
- lib32ncurses5-dev
- libncurses5-dev
- make
- name: 'Linux 32-bit clang'
arch: amd64
compiler: clang
os: linux
env: CFLAGS=-m32
addons:
apt:
packages:
- gcc-multilib
- lib32ncurses5-dev
- libncurses5-dev
- make
- name: 'FreeBSD 32-bit gcc'
arch: amd64
compiler: gcc
os: freebsd
env: CFLAGS=-m32
- name: 'FreeBSD 32-bit clang'
arch: amd64
compiler: clang
os: freebsd
env: CFLAGS=-m32

addons:
apt:
packages:
- libncurses-dev
- libncurses5-dev
- make
coverity_scan:
project:
Expand All @@ -21,13 +75,7 @@ addons:
build_command: make
# https://scan.coverity.com/faq#frequency
branch_pattern: coverity_scan
jobs:
exclude:
- os: osx
compiler: gcc
os:
- linux
- osx

script: >-
if [ "${COVERITY_SCAN_BRANCH}" != 1 ] ;
then ./configure && make && make test ;
Expand Down
2 changes: 2 additions & 0 deletions Fixes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
10. Block SIGHUP while writing history/directory stack (Brett Frankenberger)
9. Fixed reversed test that broke history merging (Brett Frankenberger)
8. Prevent recursive entry for writing history (Brett Frankenberger)
7. alxwded@github, keep track of the :g and :a modifiers per modifier they
affect.
Expand Down
7 changes: 6 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# things; Paul Placeway, CIS Dept., Ohio State University
#
SHELL=/bin/sh
ENVCMD=/usr/bin/env
VERSION=@PACKAGE_VERSION@
BUILD=tcsh$(EXEEXT)
VPATH=@srcdir@
Expand Down Expand Up @@ -634,6 +635,8 @@ veryclean: clean
${RM} -f Makefile config.h config_p.h
${RM} -f config.status config.cache config.log tcsh.ps
${RM} -f missing
${RM} -f testsuite.log
${RM} -rf testsuite.dir
${RM} -rf autom4te.cache
${RM} -f *~ #*

Expand Down Expand Up @@ -736,7 +739,9 @@ $(srcdir)/stamp-h.in: $(srcdir)/configure.ac
@echo timestamp > $(srcdir)/stamp-h.in

check test: atconfig $(srcdir)/tests/testsuite
$(SHELL) $(srcdir)/tests/testsuite
$(ENVCMD) - \
USER="$(USER)" \
$(SHELL) $(srcdir)/tests/testsuite

#
# Dependencies
Expand Down
7 changes: 6 additions & 1 deletion sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ add_localedir_to_nlspath(const char *path)
if (path == NULL)
return;

(void) xsnprintf(trypath, sizeof(trypath), "%s/en/LC_MESSAGES/tcsh.cat",
(void) xsnprintf(trypath, sizeof(trypath), "%s/C/LC_MESSAGES/tcsh.cat",
path);
if (stat(trypath, &st) == -1)
return;
Expand Down Expand Up @@ -2521,14 +2521,19 @@ static void
record(void)
{
static int again = 0;
int ophup_disabled;

if (again++)
return;

ophup_disabled = phup_disabled;
phup_disabled = 1;
if (!fast) {
recdirs(NULL, adrof(STRsavedirs) != NULL);
rechist(NULL, adrof(STRsavehist) != NULL);
}
displayHistStats("Exiting"); /* no-op unless DEBUG_HIST */
phup_disabled = ophup_disabled;
}

/*
Expand Down
41 changes: 24 additions & 17 deletions sh.dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static void dextract (struct directory *);
static int skipargs (Char ***, const char *,
const char *);
static void dgetstack (void);
static Char *dcanon_internal(Char *, Char *);

static struct directory dhead INIT_ZERO_STRUCT; /* "head" of loop */
static int printd; /* force name to be printed */
Expand Down Expand Up @@ -148,16 +149,10 @@ dinit(Char *hp)
cleanup_push(tcp, xfree);
}
}
cleanup_push(tcp, xfree);
cp = dcanon(tcp, STRNULL);
cleanup_ignore(tcp);
cleanup_until(tcp);
}
#else /* S_IFLNK */
cleanup_push(tcp, xfree);
cp = dcanon(tcp, STRNULL);
cleanup_ignore(tcp);
cleanup_until(tcp);
#endif /* S_IFLNK */
}

Expand Down Expand Up @@ -313,7 +308,7 @@ dtilde(void)
do {
if (d == &dhead)
continue;
d->di_name = dcanon(d->di_name, STRNULL);
d->di_name = dcanon_internal(d->di_name, STRNULL);
} while ((d = d->di_prev) != dcwd);

dset(dcwd->di_name);
Expand Down Expand Up @@ -571,16 +566,10 @@ dgoto(Char *cp)
if (ABSOLUTEP(cp) && cp[1] == ':') { /* Only DOS paths are treated that way */
return agetcwd();
} else {
cleanup_push(cp, xfree);
ret = dcanon(cp, dp);
cleanup_ignore(cp);
cleanup_until(cp);
}
#else /* !WINNT_NATIVE */
cleanup_push(cp, xfree);
ret = dcanon(cp, dp);
cleanup_ignore(cp);
cleanup_until(cp);
#endif /* WINNT_NATIVE */
return ret;
}
Expand Down Expand Up @@ -868,12 +857,26 @@ dfree(struct directory *dp)
}

/*
* dcanon - canonicalize the pathname, removing excess ./ and ../ etc.
* dcanon - a safe version of dcanon_internal that arranges for cleanup
*/
Char *
dcanon(Char *cp, Char *p)
{
cleanup_push(cp, xfree);
p = dcanon_internal(cp, p);
// coverity[use_after_free] we use the pointer as a marker
cleanup_ignore(cp);
cleanup_until(cp);
return p;
}

/*
* dcanon_internal - canonicalize the pathname, removing excess ./ and ../ etc.
* we are of course assuming that the file system is standardly
* constructed (always have ..'s, directories have links)
*/
Char *
dcanon(Char *cp, Char *p)
static Char *
dcanon_internal(Char *cp, Char *p)
{
Char *sp;
Char *p1, *p2; /* general purpose */
Expand Down Expand Up @@ -1356,7 +1359,7 @@ loaddirs(Char *fname)
void
recdirs(Char *fname, int def)
{
int fp, ftmp, oldidfds;
int fp, ftmp, oldidfds, ophup_disabled;
int cdflag = 0;
struct directory *dp;
unsigned int num;
Expand All @@ -1366,6 +1369,8 @@ recdirs(Char *fname, int def)
if (fname == NULL && !def)
return;

ophup_disabled = phup_disabled;
phup_disabled = 1;
if (fname == NULL) {
if ((fname = varval(STRdirsfile)) == STRNULL)
fname = Strspl(varval(STRhome), &STRtildotdirs[1]);
Expand All @@ -1378,6 +1383,7 @@ recdirs(Char *fname, int def)

if ((fp = xcreat(short2str(fname), 0600)) == -1) {
cleanup_until(fname);
phup_disabled = ophup_disabled;
return;
}

Expand Down Expand Up @@ -1413,4 +1419,5 @@ recdirs(Char *fname, int def)
SHOUT = ftmp;
didfds = oldidfds;
cleanup_until(fname);
phup_disabled = ophup_disabled;
}
4 changes: 2 additions & 2 deletions sh.dol.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ fixDolMod(void)
ndolflags = 0;
do {
++ndolflags;
dolmcnts = xrealloc(dolmcnts, ndolflags);
dolaflags = xrealloc(dolaflags, ndolflags);
dolmcnts = xrealloc(dolmcnts, ndolflags * sizeof(int));
dolaflags = xrealloc(dolaflags, ndolflags * sizeof(int));
c = DgetC(0), dolmcnts[ndolflags - 1] = 1, dolaflags[ndolflags - 1] = 0;
if (c == 'g' || c == 'a') {
if (c == 'g') {
Expand Down
3 changes: 1 addition & 2 deletions sh.func.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,9 +1517,8 @@ dosetenv(Char **v, struct command *c)
/*
* convert to canonical pathname (possibly resolving symlinks)
*/
canon = dcanon(lp, lp);
cleanup_ignore(lp);
cleanup_until(lp);
canon = dcanon(lp, lp);
cleanup_push(canon, xfree);
setv(STRhome, quote(canon), VAR_READWRITE); /* lp memory used here */
cleanup_ignore(canon);
Expand Down
11 changes: 9 additions & 2 deletions sh.glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ globtilde(Char *s)
Char *name, *u, *home, *res;

u = s;

if (s[1] == '~')
return Strsave(s);

for (s++; *s && *s != '/' && *s != ':'; s++)
continue;

name = Strnsave(u + 1, s - (u + 1));
cleanup_push(name, xfree);
home = gethdir(name);
Expand Down Expand Up @@ -513,14 +518,16 @@ globone(Char *str, int action)
}
result:
if (vl && vl[0] == NULL) {
xfree(vl);
if (vl != v)
xfree(vl);
return (Strsave(STRNULL));
}
if (vl && vl[1])
return (handleone(str, vl, action));
else {
str = strip(*vl);
xfree(vl);
if (vl != v)
xfree(vl);
return (str);
}
}
Expand Down
10 changes: 8 additions & 2 deletions sh.hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,18 @@ void
rechist(Char *fname, int ref)
{
Char *snum, *rs;
int fp, ftmp, oldidfds;
int fp, ftmp, oldidfds, ophup_disabled;
struct varent *shist;
char path[MAXPATHLEN];
struct stat st;
static Char *dumphist[] = {STRhistory, STRmhT, 0, 0};

if (fname == NULL && !ref)
return;

ophup_disabled = phup_disabled;
phup_disabled = 1;

/*
* If $savehist is just set, we use the value of $history
* else we use the value in $savehist
Expand Down Expand Up @@ -1292,7 +1296,7 @@ rechist(Char *fname, int ref)
#endif
}
getexit(osetexit);
if (setexit())
if (setexit() == 0)
loadhist(fname, 1);
resexit(osetexit);
}
Expand All @@ -1305,6 +1309,7 @@ rechist(Char *fname, int ref)
if (fp == -1) {
didfds = oldidfds;
cleanup_until(fname);
phup_disabled = ophup_disabled;
return;
}
/* Try to preserve ownership and permissions of the original history file */
Expand All @@ -1329,6 +1334,7 @@ rechist(Char *fname, int ref)
(void)ReplaceFile( short2str(fname),path,NULL,0,NULL,NULL);
#endif
cleanup_until(fname);
phup_disabled = ophup_disabled;
}


Expand Down
Loading

0 comments on commit 7c3ca17

Please sign in to comment.