tags 347232 + patch
quit

On Mon, Jan 09, 2006 at 04:29:19PM +0100, Marco Nenciarini wrote:
> The problem is here:
> 
> # Set the kernel 2.6 option only for fresh install
> test -z "$(GetMenuOpt "kopt" "")" && kopt_2_6="root=$root_device_2_6 ro"
> 
> # Extract options for specific kernels
> eval $(ExtractMenuOpts "\(kopt_[a-zA-Z0-9_]\+\)")
> 
> If the first test fails and the eval argument is empty then dash
> terminate with exitcode 1.

> This is a simple testcase:
> tm:~# bash -c "set -e ;/bin/false && : ; eval ''; echo 'END'"; echo $?
> END
> 0
> tm:~# dash -c "set -e ;/bin/false && : ; eval ''; echo 'END'"; echo $?
> 1
> 
> if you insert any command with successfull exit status before the
> empty eval, all work ok:
> tm:~# bash -c "set -e ;/bin/false && : ; : ; eval ''; echo 'END'"; echo $?
> END
> 0
> tm:~# dash -c "set -e ;/bin/false && : ; : ; eval ''; echo 'END'"; echo $?
> END
> 0

Yes, I can confirm this is a bug in dash.  The standard says

 EXIT STATUS

     If there are no arguments, or only null arguments, eval shall
     return a zero exit status; otherwise, it shall return the exit
     status of the command defined by the string of concatenated
     arguments separated by <space>s.

Hi Herbert, please see http://bugs.debian.org/347232

Below is a patch I suggest.

Regards, Gerrit.
Index: src/eval.c
===================================================================
RCS file: /cvs/dash/src/eval.c,v
retrieving revision 1.3
diff -u -r1.3 eval.c
--- src/eval.c  28 Nov 2005 11:05:29 -0000      1.3
+++ src/eval.c  10 Jan 2006 10:13:58 -0000
@@ -140,19 +140,21 @@
                 p = argv[1];
                 if (argc > 2) {
                         STARTSTACKSTR(concat);
-                        ap = argv + 2;
-                        for (;;) {
+                        for (ap = argv + 1; (p = *ap); ++ap) {
+                                if (!*p) continue;
                                concat = stputs(p, concat);
-                                if ((p = *ap++) == NULL)
+                                if (*(ap + 1) == NULL)
                                         break;
                                 STPUTC(' ', concat);
                         }
                         STPUTC('\0', concat);
                         p = grabstackstr(concat);
                 }
+                if (!*p) return 0;
                 evalstring(p, ~SKIPEVAL);
                 
         }
+        else return 0;
         return exitstatus;
 }
 

Reply via email to