hush: fix readonly2.tests failure
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 18 Jul 2017 13:58:02 +0000 (15:58 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 18 Jul 2017 13:58:02 +0000 (15:58 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c
shell/hush_test/hush-vars/readonly2.right
shell/hush_test/hush-vars/readonly2.tests

index 55e581e16bf8c3bdc7fd046260a98cedf370d257..f6da826d3bd6656dd39ba0be5ecd2de6f190a3fa 100644 (file)
@@ -2287,7 +2287,18 @@ static struct variable *set_vars_and_save_old(char **strings)
                        if (var_pp) {
                                var_p = *var_pp;
                                if (var_p->flg_read_only) {
+                                       char **p;
                                        bb_error_msg("%s: readonly variable", *s);
+                                       /*
+                                        * "VAR=V BLTIN" unsets VARs after BLTIN completes.
+                                        * If VAR is readonly, leaving it in the list
+                                        * after asssignment error (msg above)
+                                        * causes doubled error message later, on unset.
+                                        */
+                                       debug_printf_env("removing/freeing '%s' element\n", *s);
+                                       free(*s);
+                                       p = s;
+                                       do { *p = p[1]; p++; } while (*p);
                                        goto next;
                                }
                                /* Remove variable from global linked list */
index 5b02ddfe8c627016971c244647d5a3518f4a429c..38551d4ad7e2e82a836b51c2a91132b23d5d8e44 100644 (file)
@@ -1,4 +1,5 @@
 hush: a=Z: readonly variable
 Visible:42
+
 hush: a=Z: readonly variable
 Visible:42
index d9d178edd7b9e4e5c67e3654df19415d518da5b0..b758d9602407ac2254c3839120a01a92db7309b9 100755 (executable)
@@ -3,4 +3,5 @@ readonly a=A
 
 # external commands and builtins should behave the same:
 (exit 42); a=Z echo "Visible:$?"
+echo
 (exit 42); a=Z env echo "Visible:$?"