7dcb9dff3f63cee679c76724805cc0de7b04d33f
[openwrt/staging/stintel.git] / package / utils / busybox / patches / 001-CVE-2022-30065-awk-fix-use-after-free.patch
1 From e63d7cdfdac78c6fd27e9e63150335767592b85e Mon Sep 17 00:00:00 2001
2 From: Natanael Copa <ncopa@alpinelinux.org>
3 Date: Fri, 17 Jun 2022 17:45:34 +0200
4 Subject: awk: fix use after free (CVE-2022-30065)
5
6 fixes https://bugs.busybox.net/show_bug.cgi?id=14781
7
8 function old new delta
9 evaluate 3343 3357 +14
10
11 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
13 ---
14 editors/awk.c | 3 +++
15 testsuite/awk.tests | 6 ++++++
16 2 files changed, 9 insertions(+)
17
18 --- a/editors/awk.c
19 +++ b/editors/awk.c
20 @@ -3114,6 +3114,9 @@ static var *evaluate(node *op, var *res)
21
22 case XC( OC_MOVE ):
23 debug_printf_eval("MOVE\n");
24 + /* make sure that we never return a temp var */
25 + if (L.v == TMPVAR0)
26 + L.v = res;
27 /* if source is a temporary string, jusk relink it to dest */
28 if (R.v == TMPVAR1
29 && !(R.v->type & VF_NUMBER)
30 --- a/testsuite/awk.tests
31 +++ b/testsuite/awk.tests
32 @@ -469,4 +469,10 @@ testing 'awk printf %% prints one %' \
33 "%\n" \
34 '' ''
35
36 +testing 'awk assign while test' \
37 + "awk '\$1==\$1=\"foo\" {print \$1}'" \
38 + "foo\n" \
39 + "" \
40 + "foo"
41 +
42 exit $FAILCOUNT