Skip to content

Commit f127ce3

Browse files
committed
tests: address two null argument instances
Handle two null argument cases that occur in the unit tests. One is in library code, the other is in test code. Detected by running unit tests with undefined behavior sanitizer: ```bash # build mkdir build && cd build cmake -DBUILD_CLAR=ON -DCMAKE_C_FLAGS="-fsanitize=address \ -fsanitize=undefined -fstack-usage -static-libasan" .. cmake --build . # run with asan ASAN_OPTIONS="allocator_may_return_null=1" ./libgit2_clar ... ............../libgit2/src/apply.c:316:3: runtime error: null pointer \ passed as argument 1, which is declared to never be null ...................../libgit2/tests/apply/fromfile.c:46:3: runtime \ error: null pointer passed as argument 1, which is declared to never be null ```
1 parent 814e7ac commit f127ce3

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/apply.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ static int apply_binary(
312312
&patch->binary.old_file)) < 0)
313313
goto done;
314314

315+
/* Verify that the resulting file with the reverse patch applied matches the source file */
315316
if (source_len != reverse.size ||
316-
memcmp(source, reverse.ptr, source_len) != 0) {
317+
(source_len && memcmp(source, reverse.ptr, source_len) != 0)) {
317318
error = apply_err("binary patch did not apply cleanly");
318319
goto done;
319320
}

tests/apply/fromfile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static int apply_patchfile(
4343

4444
if (error == 0) {
4545
cl_assert_equal_i(new_len, result.size);
46-
cl_assert(memcmp(new, result.ptr, new_len) == 0);
46+
if (new_len)
47+
cl_assert(memcmp(new, result.ptr, new_len) == 0);
4748

4849
cl_assert_equal_s(filename_expected, filename);
4950
cl_assert_equal_i(mode_expected, mode);

0 commit comments

Comments
 (0)