tags 276964 + patch
quit

On Tue, Feb 22, 2005 at 02:05:23PM +0100, Jeroen van Wolffelaar wrote:
> On Tue, Feb 22, 2005 at 01:43:17AM +0100, Jeroen van Wolffelaar wrote:
> > | elif ! eval $mysqlcmd -f $dbname -e "\"$statement\"" >/dev/null 2>&1 ; 
> > then
> > |     log="${log}Executing command to mysql."
> > |     (...)
> > | else
> > |     status=nothing
> > | fi
> > 
> > This should, even though set -e is enabled, NOT result in abortion of shell
> > execution.
> 
> Ok, this is a dash bug, #268944.
> 
> Because /bin/sh claims to be a replacement /bin/sh when installing, this
> is IMHO a critical bug -- it breaks unrelated software.

Yes, I agree.

Hi Herbert, it turns out bug #268944 'sh: wrong errexit with eval'
breaks at least one other package's postinst, raising its severity.  See
below for a patch that I think fixes the problem.

$ dash -exc 'eval false || true; false; true'
+ eval false
+ false
$ ./build-tmp/src/dash -exc 'eval false || true; false; true'
+ eval false
+ false
+ true
+ false
$ dash -exc 'fn() { false; }; fn || true; false true'
+ fn
+ false
+ true
+ false true
$ ./build-tmp/src/dash -exc 'fn() { false; }; fn || true; false true'
+ fn
+ false
+ true
+ false true
$ echo false >t
$ dash -exc '. ./t || true; false; true'
+ . ./t
+ false
$ ./build-tmp/src/dash -exc '. ./t || true; false; true'
+ . ./t
+ false
+ true
+ false
$ 

Thanks, Gerrit.
Index: src/eval.c
===================================================================
RCS file: /cvs/dash/src/eval.c,v
retrieving revision 1.1
diff -u -r1.1 eval.c
--- src/eval.c  3 Jul 2004 12:52:54 -0000       1.1
+++ src/eval.c  22 Feb 2005 19:55:47 -0000
@@ -87,6 +87,7 @@
 STATIC int skipcount;          /* number of levels to skip */
 MKINIT int loopnest;           /* current loop nesting level */
 int funcnest;                  /* depth of function calls */
+int ev_tested;
 
 
 char *commandname;
@@ -134,6 +135,7 @@
        evalskip = 0;
        loopnest = 0;
        funcnest = 0;
+       ev_tested = 0;
 }
 #endif
 
@@ -245,7 +247,13 @@
                evalcommand(n, flags, (struct backcmd *)NULL);
                break;
 #else
+               ev_tested += (flags & EV_TESTED)?1:0;
                evalfn = evalcommand;
+               if (eflag && !(flags & EV_TESTED))
+                       checkexit = ~0;
+               evalfn(n, flags);
+               ev_tested -= (flags & EV_TESTED)?1:0;
+               break;
 checkexit:
                if (eflag && !(flags & EV_TESTED))
                        checkexit = ~0;
@@ -323,7 +331,7 @@
        if (pendingsigs)
                dotrap();
        if (flags & EV_EXIT || checkexit & exitstatus)
-               exraise(EXEXIT);
+               if (! ev_tested) exraise(EXEXIT);
 }
 
 
Index: src/eval.h
===================================================================
RCS file: /cvs/dash/src/eval.h,v
retrieving revision 1.1
diff -u -r1.1 eval.h
--- src/eval.h  3 Jul 2004 12:52:54 -0000       1.1
+++ src/eval.h  22 Feb 2005 19:55:47 -0000
@@ -60,6 +60,7 @@
 #define in_function()  funcnest
 extern int funcnest;
 extern int evalskip;
+extern int ev_tested;
 
 /* reasons for skipping commands (see comment on breakcmd routine) */
 #define SKIPBREAK      1

Reply via email to