From 39ab9952e8255cb99e9c0abcc8bbec43158a55d7 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 20 Jul 2013 23:23:18 +0100 Subject: 31545: Use of FD_CLOEXEC to remove possibility of fd reuse. File descriptors of mmap'd dump files are closed if and only if an exec is performed. --- Src/parse.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Src/parse.c') diff --git a/Src/parse.c b/Src/parse.c index 753080d70..b670925de 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -3171,6 +3171,9 @@ load_dump_file(char *dump, struct stat *sbuf, int other, int len) d->dev = sbuf->st_dev; d->ino = sbuf->st_ino; d->fd = fd; +#ifdef FD_CLOEXEC + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif d->map = addr + (other ? (len - off) / sizeof(wordcode) : 0); d->addr = addr; d->len = len; @@ -3439,6 +3442,7 @@ decrdumpcount(FuncDump f) } } +#ifndef FD_CLOEXEC /**/ mod_export void closedumps(void) @@ -3448,6 +3452,7 @@ closedumps(void) for (p = dumps; p; p = p->next) zclose(p->fd); } +#endif #else @@ -3461,11 +3466,13 @@ decrdumpcount(FuncDump f) { } +#ifndef FD_CLOEXEC /**/ mod_export void closedumps(void) { } +#endif #endif -- cgit v1.2.3 From 4095e175b6dcdaf901e783752bbd5a503c27881b Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 25 Jul 2013 09:45:33 +0100 Subject: 31574: alternative fix for bad fd if no FD_CLOEXEC. Remove dump records more consistently in that case. --- ChangeLog | 5 +++++ Src/parse.c | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'Src/parse.c') diff --git a/ChangeLog b/ChangeLog index 6cd6659ba..913585d06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-07-25 Peter Stephenson + + * 31574: Src/parse.c: alternative fix to 31545 if FD_CLOEXEC is + not available, removing dump records more consistently. + 2013-07-24 Richard Hartmann * 31571: Completion/Unix/Command/_vcsh: Update diff --git a/Src/parse.c b/Src/parse.c index b670925de..0c2a45833 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -3418,6 +3418,16 @@ incrdumpcount(FuncDump f) f->count++; } +/**/ +static void +freedump(FuncDump f) +{ + munmap((void *) f->addr, f->len); + zclose(f->fd); + zsfree(f->filename); + zfree(f, sizeof(*f)); +} + /* Decrement the reference counter for a dump file. If zero, unmap the file. */ /**/ @@ -3434,10 +3444,7 @@ decrdumpcount(FuncDump f) q->next = p->next; else dumps = p->next; - munmap((void *) f->addr, f->len); - zclose(f->fd); - zsfree(f->filename); - zfree(f, sizeof(*f)); + freedump(f); } } } @@ -3447,10 +3454,11 @@ decrdumpcount(FuncDump f) mod_export void closedumps(void) { - FuncDump p; - - for (p = dumps; p; p = p->next) - zclose(p->fd); + while (dumps) { + FuncDump p = dumps->next; + freedump(dumps); + dumps = p; + } } #endif -- cgit v1.2.3 From 2afa556d8fd6b365e518ef754fc34f0ffb6854ff Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 4 Sep 2013 20:16:58 +0100 Subject: 31696: In "test" No One Can Hear If You Shriek. Treat ! as a string in "test ! -a ..." and "test ! -o ...". --- ChangeLog | 6 ++++++ Src/parse.c | 14 +++++++++++--- Test/C02cond.ztst | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) (limited to 'Src/parse.c') diff --git a/ChangeLog b/ChangeLog index 7b93632f6..6c3771271 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-09-04 Peter Stephenson + + * 31696: Src/parse.c, Test/C02cond.ztst: in "test", no one + can hear if you shriek. Treat exclamation marks as strings in + "! -a ..." and "! -o ...". + 2013-08-29 Peter Stephenson * users/17955: Doc/Zsh/contrib.yo, diff --git a/Src/parse.c b/Src/parse.c index 0c2a45833..f0d0855d3 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -2088,9 +2088,17 @@ par_cond_2(void) } } if (tok == BANG) { - condlex(); - ecadd(WCB_COND(COND_NOT, 0)); - return par_cond_2(); + /* + * In "test" compatibility mode, "! -a ..." and "! -o ..." + * are treated as "[string] [and] ..." and "[string] [or] ...". + */ + if (!(condlex == testlex && *testargs && + (!strcmp(*testargs, "-a") || !strcmp(*testargs, "-o")))) + { + condlex(); + ecadd(WCB_COND(COND_NOT, 0)); + return par_cond_2(); + } } if (tok == INPAR) { int r; diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 494261ee3..856251923 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -324,6 +324,27 @@ F:Failures in these cases do not indicate a problem in the shell. > fi >} + weirdies=( + '! -a !' + '! -o !' + '! -a' + '! -o' + '! -a ! -a !' + '! = !' + '! !') + for w in $weirdies; do + eval test $w + print $? + done +0:test compatability weirdness: treat ! as a string sometimes +>0 +>0 +>1 +>0 +>0 +>0 +>1 + %clean # This works around a bug in rm -f in some versions of Cygwin chmod 644 unmodish -- cgit v1.2.3