NEEDS WORK: add memory santizier to Git
This MR needs work, not sure how much...
Currently, I'm stuck on fixing one of the unused variables.
Ideal fix
You can see that this requires polluting the code with msan_unpoison() in the code. Ideally, this would be restricted to the wrapper.c code, since that is the interface for most libraries, and adding msan_unpoison() there would be acceptable. If we get around fixing these issues, we could then add a CI job for the memory sanitizer.
Setup
# Setup a build directory configured to run the sanitizer
$ meson setup --reconfigure memory . --fatal-meson-warnings --warnlevel 2 --werror --wrap-mode nofallback -Dfuzzers=true -Db_sanitize=memory -Db_lundef=false
# Run the sanitizer on a test
$ cd memory
$ meson test -v --test-args='-ix' t0610-reftable-basics
...
Current Issue
I'm not sure how to fix this one, I thought that the output buffer used in deflate() was the issue. But adding an unpoison there didn't help.
Uninitialized bytes in write at offset 0 inside [0x7ffe06dbae30, 17)
==31030==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55dd91d907ca in xwrite ../wrapper.c:256:8
#1 0x55dd91d91f2f in write_in_full ../wrapper.c:311:21
#2 0x55dd91208999 in write_loose_object_common ../object-file.c:809:6
#3 0x55dd9120d7e3 in write_loose_object ../object-file.c:871:9
#4 0x55dd9120c535 in write_object_file ../object-file.c:1073:6
#5 0x55dd912850e8 in odb_write_object_ext ../odb.c:990:9
#6 0x55dd9121573b in odb_write_object ../odb.h:475:9
#7 0x55dd91220a7d in index_mem ../object-file.c:1166:9
#8 0x55dd912136f1 in index_core ../object-file.c:1236:10
#9 0x55dd91210f73 in index_fd ../object-file.c:1263:9
#10 0x55dd91214680 in index_path ../object-file.c:1284:7
#11 0x55dd91556c20 in add_to_index ../read-cache.c:771:7
#12 0x55dd9155aba9 in add_file_to_index ../read-cache.c:804:9
#13 0x55dd8fe6f2fc in add_files ../builtin/add.c:359:7
#14 0x55dd8fe68bb5 in cmd_add ../builtin/add.c:592:18
#15 0x55dd90793e0d in run_builtin ../git.c:480:11
#16 0x55dd90789bca in handle_builtin ../git.c:746:9
#17 0x55dd90790713 in run_argv ../git.c:813:4
#18 0x55dd90788401 in cmd_main ../git.c:953:19
#19 0x55dd90799c5f in main ../common-main.c:9:11
#20 0x7f3e0142a4d7 in __libc_start_call_main (/nix/store/lmn7lwydprqibdkghw7wgcn21yhllz13-glibc-2.40-66/lib/libc.so.6+0x2a4d7) (BuildId: 3d3604f0bf1f8d0e1f8fd4aeb31d0221bd6699e3)
#21 0x7f3e0142a59a in __libc_start_main@GLIBC_2.2.5 (/nix/store/lmn7lwydprqibdkghw7wgcn21yhllz13-glibc-2.40-66/lib/libc.so.6+0x2a59a) (BuildId: 3d3604f0bf1f8d0e1f8fd4aeb31d0221bd6699e3)
#22 0x55dd8fdc4b74 in _start (git+0x5db74)
Uninitialized value was stored to memory at
#0 0x55dd8fe0d75a in __msan_memcpy.part.0 msan_interceptors.cpp.o
#1 0x7f3e01857f02 in zng_flush_pending (/nix/store/36nlna11vlyj1n4lvxy3rcpm36z6zcb8-zlib-ng-2.2.4/lib/libz-ng.so.2+0x5f02)
#2 0x7f3e0185aff1 in deflate_quick (/nix/store/36nlna11vlyj1n4lvxy3rcpm36z6zcb8-zlib-ng-2.2.4/lib/libz-ng.so.2+0x8ff1)
#3 0x7f3e0185804c in zng_deflate (/nix/store/36nlna11vlyj1n4lvxy3rcpm36z6zcb8-zlib-ng-2.2.4/lib/libz-ng.so.2+0x604c)
#4 0x55dd90efbc87 in git_deflate ../git-zlib.c:247:12
#5 0x55dd91208345 in write_loose_object_common ../object-file.c:805:8
#6 0x55dd9120d7e3 in write_loose_object ../object-file.c:871:9
#7 0x55dd9120c535 in write_object_file ../object-file.c:1073:6
#8 0x55dd912850e8 in odb_write_object_ext ../odb.c:990:9
#9 0x55dd9121573b in odb_write_object ../odb.h:475:9
#10 0x55dd91220a7d in index_mem ../object-file.c:1166:9
#11 0x55dd912136f1 in index_core ../object-file.c:1236:10
#12 0x55dd91210f73 in index_fd ../object-file.c:1263:9
#13 0x55dd91214680 in index_path ../object-file.c:1284:7
#14 0x55dd91556c20 in add_to_index ../read-cache.c:771:7
#15 0x55dd9155aba9 in add_file_to_index ../read-cache.c:804:9
#16 0x55dd8fe6f2fc in add_files ../builtin/add.c:359:7
#17 0x55dd8fe68bb5 in cmd_add ../builtin/add.c:592:18
#18 0x55dd90793e0d in run_builtin ../git.c:480:11
#19 0x55dd90789bca in handle_builtin ../git.c:746:9
Uninitialized value was created by a heap allocation
#0 0x55dd8fe122eb in aligned_alloc (git+0xab2eb)
#1 0x7f3e018577ae in alloc_deflate (/nix/store/36nlna11vlyj1n4lvxy3rcpm36z6zcb8-zlib-ng-2.2.4/lib/libz-ng.so.2+0x57ae)
#2 0x7f3e01858d90 in zng_deflateInit2 (/nix/store/36nlna11vlyj1n4lvxy3rcpm36z6zcb8-zlib-ng-2.2.4/lib/libz-ng.so.2+0x6d90)
#3 0x55dd90efa18b in git_deflate_init ../git-zlib.c:167:11
#4 0x55dd912070c0 in start_loose_object_common ../object-file.c:772:2
#5 0x55dd9120d35f in write_loose_object ../object-file.c:859:7
#6 0x55dd9120c535 in write_object_file ../object-file.c:1073:6
#7 0x55dd912850e8 in odb_write_object_ext ../odb.c:990:9
#8 0x55dd9121573b in odb_write_object ../odb.h:475:9
#9 0x55dd91220a7d in index_mem ../object-file.c:1166:9
#10 0x55dd912136f1 in index_core ../object-file.c:1236:10
#11 0x55dd91210f73 in index_fd ../object-file.c:1263:9
#12 0x55dd91214680 in index_path ../object-file.c:1284:7
#13 0x55dd91556c20 in add_to_index ../read-cache.c:771:7
#14 0x55dd9155aba9 in add_file_to_index ../read-cache.c:804:9
#15 0x55dd8fe6f2fc in add_files ../builtin/add.c:359:7
#16 0x55dd8fe68bb5 in cmd_add ../builtin/add.c:592:18
#17 0x55dd90793e0d in run_builtin ../git.c:480:11
#18 0x55dd90789bca in handle_builtin ../git.c:746:9
#19 0x55dd90790713 in run_argv ../git.c:813:4
Edited by Karthik Nayak