uci: Backport security fixes
[librecmc/librecmc.git] / package / system / uci / patches / 001-file-uci_parse_package-fix-heap-use-after-free.patch
1 From a3e650911f5e6f67dcff09974df3775dfd615da6 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= <ynezz@true.cz>
3 Date: Sat, 3 Oct 2020 01:29:21 +0200
4 Subject: [PATCH] file: uci_parse_package: fix heap use after free
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Fixes following issue which is caused by usage of pointer which pointed
10 to a reallocated address:
11
12  ERROR: AddressSanitizer: heap-use-after-free on address 0x619000000087 at pc 0x000000509aa7 bp 0x7ffd6b9c3c40 sp 0x7ffd6b9c3400
13  READ of size 2 at 0x619000000087 thread T0
14      #0 0x509aa6 in strdup (test-fuzz+0x509aa6)
15      #1 0x7fc36d2a1636 in uci_strdup util.c:60:8
16      #2 0x7fc36d29e1ac in uci_alloc_generic list.c:55:13
17      #3 0x7fc36d29e241 in uci_alloc_package list.c:253:6
18      #4 0x7fc36d2a0ba3 in uci_switch_config file.c:375:18
19      #5 0x7fc36d2a09b8 in uci_parse_package file.c:397:2
20      #6 0x7fc36d2a09b8 in uci_parse_line file.c:513:6
21      #7 0x7fc36d2a09b8 in uci_import file.c:681:4
22
23  0x619000000087 is located 7 bytes inside of 1024-byte region [0x619000000080,0x619000000480)
24  freed by thread T0 here:
25      #0 0x51daa9 in realloc (test-fuzz+0x51daa9)
26      #1 0x7fc36d2a1612 in uci_realloc util.c:49:8
27
28  previously allocated by thread T0 here:
29      #0 0x51daa9 in realloc (test-fuzz+0x51daa9)
30      #1 0x7fc36d2a1612 in uci_realloc util.c:49:8
31
32 Reported-by: Jeremy Galindo <jgalindo@datto.com>
33 Signed-off-by: Petr Štetiar <ynezz@true.cz>
34 ---
35  file.c                                             |   2 +-
36  ...sig-06,src-000079,time-22005942,op-ext_AO,pos-8 | Bin 0 -> 56 bytes
37  2 files changed, 1 insertion(+), 1 deletion(-)
38  create mode 100644 tests/fuzz/corpus/id-000000,sig-06,src-000079,time-22005942,op-ext_AO,pos-8
39
40 --- a/file.c
41 +++ b/file.c
42 @@ -388,8 +388,8 @@ static void uci_parse_package(struct uci
43         pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
44  
45         ofs_name = next_arg(ctx, true, true, true);
46 -       name = pctx_str(pctx, ofs_name);
47         assert_eol(ctx);
48 +       name = pctx_str(pctx, ofs_name);
49         if (single)
50                 return;
51