[git commit] awk: fix use after free (CVE-2022-30065)

Denys Vlasenko vda.linux at googlemail.com
Mon Jul 11 15:18:07 UTC 2022


commit: https://git.busybox.net/busybox/commit/?id=e63d7cdfdac78c6fd27e9e63150335767592b85e
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

fixes https://bugs.busybox.net/show_bug.cgi?id=14781

function                                             old     new   delta
evaluate                                            3343    3357     +14

Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/awk.c       | 3 +++
 testsuite/awk.tests | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/editors/awk.c b/editors/awk.c
index 079d0bde5..728ee8685 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -3128,6 +3128,9 @@ static var *evaluate(node *op, var *res)
 
 		case XC( OC_MOVE ):
 			debug_printf_eval("MOVE\n");
+			/* make sure that we never return a temp var */
+			if (L.v == TMPVAR0)
+				L.v = res;
 			/* if source is a temporary string, jusk relink it to dest */
 			if (R.v == TMPVAR1
 			 && !(R.v->type & VF_NUMBER)
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index 93e25d8c1..bbf0fbff1 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -479,4 +479,10 @@ testing 'awk backslash+newline eaten with no trace' \
 	"Hello world\n" \
 	'' ''
 
+testing 'awk assign while test' \
+	"awk '\$1==\$1=\"foo\" {print \$1}'" \
+	"foo\n" \
+	"" \
+	"foo"
+
 exit $FAILCOUNT


More information about the busybox-cvs mailing list