aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-18 01:40:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-18 01:40:01 +0200
commit38ef39a1abd46ca390b0259ebd0b35e9ea9ccb68 (patch)
tree7c2f7de98cd1a7b467be6529eff98c23b999af17
parent3bab36b18baa0dc254445828f492051450a38d41 (diff)
downloadbusybox-w32-38ef39a1abd46ca390b0259ebd0b35e9ea9ccb68.tar.gz
busybox-w32-38ef39a1abd46ca390b0259ebd0b35e9ea9ccb68.tar.bz2
busybox-w32-38ef39a1abd46ca390b0259ebd0b35e9ea9ccb68.zip
hush: add readonly testcase, fix fallout
function old new delta helper_export_local 185 214 +29 run_pipe 1549 1560 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0) Total: 40 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c26
-rw-r--r--shell/hush_test/hush-vars/readonly0.right12
-rwxr-xr-xshell/hush_test/hush-vars/readonly0.tests24
3 files changed, 53 insertions, 9 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 7771172b6..eab1284f6 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -7767,10 +7767,10 @@ static NOINLINE int run_pipe(struct pipe *pi)
7767 if (new_env) { 7767 if (new_env) {
7768 argv = new_env; 7768 argv = new_env;
7769 while (*argv) { 7769 while (*argv) {
7770 set_local_var(*argv, /*flag:*/ 0); 7770 if (set_local_var(*argv, /*flag:*/ 0)) {
7771 /* Do we need to flag set_local_var() errors? 7771 /* assignment to readonly var / putenv error? */
7772 * "assignment to readonly var" and "putenv error" 7772 rcode = 1;
7773 */ 7773 }
7774 argv++; 7774 argv++;
7775 } 7775 }
7776 } 7776 }
@@ -7795,10 +7795,10 @@ static NOINLINE int run_pipe(struct pipe *pi)
7795 fprintf(stderr, " %s", p); 7795 fprintf(stderr, " %s", p);
7796 debug_printf_exec("set shell var:'%s'->'%s'\n", 7796 debug_printf_exec("set shell var:'%s'->'%s'\n",
7797 *argv, p); 7797 *argv, p);
7798 set_local_var(p, /*flag:*/ 0); 7798 if (set_local_var(p, /*flag:*/ 0)) {
7799 /* Do we need to flag set_local_var() errors? 7799 /* assignment to readonly var / putenv error? */
7800 * "assignment to readonly var" and "putenv error" 7800 rcode = 1;
7801 */ 7801 }
7802 argv++; 7802 argv++;
7803 } 7803 }
7804 if (G_x_mode) 7804 if (G_x_mode)
@@ -9336,6 +9336,13 @@ static int helper_export_local(char **argv, unsigned flags)
9336 continue; 9336 continue;
9337 } 9337 }
9338 } 9338 }
9339 if (flags & SETFLAG_MAKE_RO) {
9340 /* readonly NAME (without =VALUE) */
9341 if (var) {
9342 var->flg_read_only = 1;
9343 continue;
9344 }
9345 }
9339# if ENABLE_HUSH_LOCAL 9346# if ENABLE_HUSH_LOCAL
9340 /* Is this "local" bltin? */ 9347 /* Is this "local" bltin? */
9341 if (!(flags & (SETFLAG_EXPORT|SETFLAG_UNEXPORT|SETFLAG_MAKE_RO))) { 9348 if (!(flags & (SETFLAG_EXPORT|SETFLAG_UNEXPORT|SETFLAG_MAKE_RO))) {
@@ -9364,7 +9371,8 @@ static int helper_export_local(char **argv, unsigned flags)
9364 /* (Un)exporting/making local NAME=VALUE */ 9371 /* (Un)exporting/making local NAME=VALUE */
9365 name = xstrdup(name); 9372 name = xstrdup(name);
9366 } 9373 }
9367 set_local_var(name, flags); 9374 if (set_local_var(name, flags))
9375 return EXIT_FAILURE;
9368 } while (*++argv); 9376 } while (*++argv);
9369 return EXIT_SUCCESS; 9377 return EXIT_SUCCESS;
9370} 9378}
diff --git a/shell/hush_test/hush-vars/readonly0.right b/shell/hush_test/hush-vars/readonly0.right
new file mode 100644
index 000000000..9688d2e5f
--- /dev/null
+++ b/shell/hush_test/hush-vars/readonly0.right
@@ -0,0 +1,12 @@
1readonly a=A
2readonly b=B
3Ok:0
4hush: a=A: readonly variable
5Fail:1
6hush: a=A: readonly variable
7Fail:1
8hush: a=A: readonly variable
9Fail:1
10Visible:0
11hush: a: readonly variable
12Fail:1
diff --git a/shell/hush_test/hush-vars/readonly0.tests b/shell/hush_test/hush-vars/readonly0.tests
new file mode 100755
index 000000000..3845f76ac
--- /dev/null
+++ b/shell/hush_test/hush-vars/readonly0.tests
@@ -0,0 +1,24 @@
1readonly a=A
2b=B
3readonly b
4# readonly on already readonly var is harmless
5readonly b a
6readonly | grep '^readonly [ab]='
7# this should work
8export a b
9export -n a b
10echo Ok:$?
11env | grep -e^a= -e^b= # shows nothing
12
13# these should all fail (despite the same value being assigned)
14# bash does not abort even in non-interactive more (in script)
15true
16a=A
17echo Fail:$?; true
18readonly a=A
19echo Fail:$?; true
20export a=A
21echo Fail:$?; true
22a=A echo Visible:$? # command still runs
23unset a
24echo Fail:$?; true