Skip to content

Commit 67e0f41

Browse files
authored
[dfsan] Make sprintf interceptor compatible with glibc 2.37+ and musl (#78363)
snprintf interceptors call `format_buffer` with `size==~0ul`, which may eventually lead to `snprintf(s, n, "Hello world!")` where `s+n` wraps around. Since glibc 2.37 (https://sourceware.org/PR30441), the snprintf call does not write the last char. musl snprintf returns -1 with EOVERFLOW when `n > INT_MAX`. Change `size` to INT_MAX to work with glibc 2.37+ and musl. snprintf interceptors are not changed. It's user responsibility to not cause a compatibility issue with libc implementations. Fix #60678
1 parent 430a40d commit 67e0f41

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

compiler-rt/lib/dfsan/dfsan_custom.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,7 +2792,7 @@ int __dfsw_sprintf(char *str, const char *format, dfsan_label str_label,
27922792
va_list ap;
27932793
va_start(ap, ret_label);
27942794

2795-
int ret = format_buffer(str, ~0ul, format, va_labels, ret_label, nullptr,
2795+
int ret = format_buffer(str, INT32_MAX, format, va_labels, ret_label, nullptr,
27962796
nullptr, ap);
27972797
va_end(ap);
27982798
return ret;
@@ -2806,8 +2806,8 @@ int __dfso_sprintf(char *str, const char *format, dfsan_label str_label,
28062806
dfsan_origin *ret_origin, ...) {
28072807
va_list ap;
28082808
va_start(ap, ret_origin);
2809-
int ret = format_buffer(str, ~0ul, format, va_labels, ret_label, va_origins,
2810-
ret_origin, ap);
2809+
int ret = format_buffer(str, INT32_MAX, format, va_labels, ret_label,
2810+
va_origins, ret_origin, ap);
28112811
va_end(ap);
28122812
return ret;
28132813
}

compiler-rt/test/dfsan/custom.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// https://github.com/llvm/llvm-project/issues/60678
2-
// XFAIL: glibc-2.37
3-
41
// RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
52
// RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
63
// RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm -dfsan-combine-pointer-labels-on-load=false -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t

compiler-rt/test/dfsan/release_shadow_space.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// https://github.com/llvm/llvm-project/issues/60678
2-
// XFAIL: glibc-2.37
3-
41
// DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s -o %t && %run %t
52
// DFSAN_OPTIONS=no_huge_pages_for_shadow=true RUN: %clang_dfsan %s -o %t && %run %t
63
// DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -o %t && %run %t

0 commit comments

Comments
 (0)