Closed orbea closed 2 years ago
Right, that's legitimate. Now I understand why Rust is a thing
Can you retry?
With commit 13465dca3426752d412b97524b166d1ed55d8068.
$ ./libtree /usr/lib64/libLLVMScalarOpts.so
=================================================================
==25431==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffded805c8 at pc 0x0000004d2bd6 bp 0x7fffded80510 sp 0x7fffded80508
READ of size 8 at 0x7fffded805c8 thread T0
#0 0x4d2bd5 in string_table_maybe_grow /tmp/libtree/libtree.c:302:12
#1 0x4d536d in interpolate_variables /tmp/libtree/libtree.c:519:9
#2 0x4cf9c5 in recurse /tmp/libtree/libtree.c:1141:13
#3 0x4cc86c in print_tree /tmp/libtree/libtree.c:1468:22
#4 0x4cc4b3 in main /tmp/libtree/libtree.c:1634:12
#5 0x7f9d392d401c in __libc_start_main (/lib64/libc.so.6+0x2401c)
#6 0x41f369 in _start /tmp/glibc-2.33/csu/../sysdeps/x86_64/start.S:120
Address 0x7fffded805c8 is located in stack of thread T0 at offset 40 in frame
#0 0x4d47af in interpolate_variables /tmp/libtree/libtree.c:442
This frame has 1 object(s):
[32, 40) 'st' (line 447) <== Memory access at offset 40 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /tmp/libtree/libtree.c:302:12 in string_table_maybe_grow
Shadow bytes around the buggy address:
0x10007bda8060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda8070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda8080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda8090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda80a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10007bda80b0: 00 00 00 00 f1 f1 f1 f1 00[f3]f3 f3 00 00 00 00
0x10007bda80c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda80d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda80e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda80f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007bda8100: 00 00 00 00 f1 f1 f1 f1 00 00 f2 f2 00 00 f2 f2
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==25431==ABORTING
Also a new compiler warning fwiw.
clang -g -O0 -fsanitize=address -Wall -std=c99 -D_FILE_OFFSET_BITS=64 -c libtree.c
libtree.c:519:33: warning: incompatible pointer types passing 'struct string_table_t **' to parameter of type 'struct string_table_t *'; remove & [-Wincompatible-pointer-types]
string_table_maybe_grow(&st, n);
^~~
libtree.c:300:60: note: passing argument to parameter 't' here
static void string_table_maybe_grow(struct string_table_t *t, size_t n) {
^
1 warning generated.
4f16a1be6a591424a8b1b1658bb61a64495aee0d yes, sorry
Works with commit 4f16a1be6a591424a8b1b1658bb61a64495aee0d, thanks again!
$ ./libtree /usr/lib64/libLLVMScalarOpts.so
libLLVMScalarOpts.so.12
├── libLLVMAggressiveInstCombine.so.12 [runpath]
│ ├── libLLVMTransformUtils.so.12 [runpath]
│ │ ├── libLLVMAnalysis.so.12 [runpath]
│ │ │ ├── libLLVMObject.so.12 [runpath]
│ │ │ │ ├── libLLVMBitReader.so.12 [runpath]
│ │ │ │ │ ├── libLLVMCore.so.12 [runpath]
│ │ │ │ │ │ ├── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ │ │ ├── libLLVMDemangle.so.12 [runpath]
│ │ │ │ │ │ │ ├── libz.so.1 [runpath]
│ │ │ │ │ │ │ ├── libtinfo.so.6 [runpath]
│ │ │ │ │ │ │ └── librt.so.1 [ld.so.conf]
│ │ │ │ │ │ ├── libLLVMRemarks.so.12 [runpath]
│ │ │ │ │ │ │ ├── libLLVMBitstreamReader.so.12 [runpath]
│ │ │ │ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ │ └── libLLVMBinaryFormat.so.12 [runpath]
│ │ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ ├── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ └── libLLVMBitstreamReader.so.12 [runpath]
│ │ │ │ ├── libLLVMSupport.so.12 [runpath]
│ │ │ │ ├── libLLVMBinaryFormat.so.12 [runpath]
│ │ │ │ ├── libLLVMMC.so.12 [runpath]
│ │ │ │ │ ├── libLLVMBinaryFormat.so.12 [runpath]
│ │ │ │ │ ├── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ └── libLLVMDebugInfoCodeView.so.12 [runpath]
│ │ │ │ │ ├── libLLVMDebugInfoMSF.so.12 [runpath]
│ │ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ ├── libLLVMTextAPI.so.12 [runpath]
│ │ │ │ │ ├── libLLVMBinaryFormat.so.12 [runpath]
│ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ ├── libLLVMMCParser.so.12 [runpath]
│ │ │ │ │ ├── libLLVMMC.so.12 [runpath]
│ │ │ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ │ │ └── libLLVMCore.so.12 [runpath]
│ │ │ ├── libLLVMSupport.so.12 [runpath]
│ │ │ ├── libLLVMBinaryFormat.so.12 [runpath]
│ │ │ ├── libLLVMCore.so.12 [runpath]
│ │ │ └── libLLVMProfileData.so.12 [runpath]
│ │ │ ├── libLLVMCore.so.12 [runpath]
│ │ │ ├── libLLVMDemangle.so.12 [runpath]
│ │ │ └── libLLVMSupport.so.12 [runpath]
│ │ ├── libLLVMSupport.so.12 [runpath]
│ │ └── libLLVMCore.so.12 [runpath]
│ ├── libLLVMSupport.so.12 [runpath]
│ ├── libLLVMCore.so.12 [runpath]
│ └── libLLVMAnalysis.so.12 [runpath]
├── libLLVMSupport.so.12 [runpath]
├── libLLVMCore.so.12 [runpath]
├── libLLVMAnalysis.so.12 [runpath]
├── libLLVMTransformUtils.so.12 [runpath]
└── libLLVMInstCombine.so.12 [runpath]
├── libLLVMTransformUtils.so.12 [runpath]
├── libLLVMSupport.so.12 [runpath]
├── libLLVMCore.so.12 [runpath]
└── libLLVMAnalysis.so.12 [runpath]
Thanks for your patience :D
No worries, I am just testing the tool because I was curious after the c99 rewrite. It does seem rather useful.
libtree: d51185d9fa83dd0525ef135bb3c40391f42cb932