summaryrefslogtreecommitdiff
path: root/aports/busybox/0018-ash-fix-ifs-cleanup-on-error-paths.patch
blob: c09bc84daa6d136a251faa06e9cc422ce07df6ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 1c5455284234e894dfb6086bf7f3e9a6d5d9611f Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Tue, 2 Aug 2022 11:13:44 +0200
Subject: [PATCH] ash: fix ifs cleanup on error paths

Patch by Alex Gorinson <algore3698@gmail.com>

function                                             old     new   delta
evalvar                                              477     495     +18
varvalue                                             603     618     +15
subevalvar                                          1557    1572     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 48/0)               Total: 48 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 shell/ash.c                                        | 2 ++
 shell/ash_test/ash-heredoc/heredoc_and_cmd.right   | 2 ++
 shell/ash_test/ash-heredoc/heredoc_and_cmd.tests   | 8 ++++++++
 shell/hush_test/hush-heredoc/heredoc_and_cmd.right | 2 ++
 shell/hush_test/hush-heredoc/heredoc_and_cmd.tests | 8 ++++++++
 5 files changed, 22 insertions(+)
 create mode 100644 shell/ash_test/ash-heredoc/heredoc_and_cmd.right
 create mode 100755 shell/ash_test/ash-heredoc/heredoc_and_cmd.tests
 create mode 100644 shell/hush_test/hush-heredoc/heredoc_and_cmd.right
 create mode 100755 shell/hush_test/hush-heredoc/heredoc_and_cmd.tests

diff --git a/shell/ash.c b/shell/ash.c
index d29de37b7..c731a333b 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7028,6 +7028,7 @@ varunset(const char *end, const char *var, const char *umsg, int varflags)
 			msg = umsg;
 		}
 	}
+	ifsfree();
 	ash_msg_and_raise_error("%.*s: %s%s", (int)(end - var - 1), var, msg, tail);
 }
 
@@ -7453,6 +7454,7 @@ varvalue(char *name, int varflags, int flags, int quoted)
 		if (discard)
 			return -1;
 
+		ifsfree();
 		raise_error_syntax("bad substitution");
 	}
 
diff --git a/shell/ash_test/ash-heredoc/heredoc_and_cmd.right b/shell/ash_test/ash-heredoc/heredoc_and_cmd.right
new file mode 100644
index 000000000..25ae70561
--- /dev/null
+++ b/shell/ash_test/ash-heredoc/heredoc_and_cmd.right
@@ -0,0 +1,2 @@
+./heredoc_and_cmd.tests: line 4: D: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+Y
diff --git a/shell/ash_test/ash-heredoc/heredoc_and_cmd.tests b/shell/ash_test/ash-heredoc/heredoc_and_cmd.tests
new file mode 100755
index 000000000..197542de7
--- /dev/null
+++ b/shell/ash_test/ash-heredoc/heredoc_and_cmd.tests
@@ -0,0 +1,8 @@
+# The bug was only happening with <<REDIR;CMD form below:
+M='AAAAAAAAAAAAAAAAA'
+fff(){
+date <<000; echo Y
+${D?$M$M$M$M$M$M}
+000
+}
+fff
diff --git a/shell/hush_test/hush-heredoc/heredoc_and_cmd.right b/shell/hush_test/hush-heredoc/heredoc_and_cmd.right
new file mode 100644
index 000000000..5c19a0621
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_and_cmd.right
@@ -0,0 +1,2 @@
+hush: D: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+Y
diff --git a/shell/hush_test/hush-heredoc/heredoc_and_cmd.tests b/shell/hush_test/hush-heredoc/heredoc_and_cmd.tests
new file mode 100755
index 000000000..197542de7
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_and_cmd.tests
@@ -0,0 +1,8 @@
+# The bug was only happening with <<REDIR;CMD form below:
+M='AAAAAAAAAAAAAAAAA'
+fff(){
+date <<000; echo Y
+${D?$M$M$M$M$M$M}
+000
+}
+fff