https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/239764

>From fa4a08d41269d0d8dfaa790000ea28ea7e4e0d13 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <[email protected]>
Date: Fri, 6 Nov 2026 11:44:59 -0800
Subject: [PATCH] [spr] update

Created using spr 2.0.0-beta.2
---
 .../sanitizer_common_interceptors.inc                | 12 +++++++++---
 compiler-rt/test/msan/Linux/strlcpy_strlcat.c        |  9 +++++++--
 .../sanitizer_common/TestCases/Posix/strlcpy_oob.cpp | 12 ++++++++++++
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 9a8e92635653f..f855fa9081591 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7736,14 +7736,20 @@ INTERCEPTOR(SIZE_T, strlcpy, char *dst, char *src, 
SIZE_T size) {
 INTERCEPTOR(SIZE_T, strlcat, char *dst, char *src, SIZE_T size) {
   void *ctx;
   SIZE_T len = 0;
+  SIZE_T srclen = 0;
   COMMON_INTERCEPTOR_ENTER(ctx, strlcat, dst, src, size);
-  // src is checked in the strlcpy() interceptor
   if (dst && size > 0) {
     len = internal_strnlen(dst, size);
     COMMON_INTERCEPTOR_READ_RANGE(ctx, dst, Min(len + 1, size));
   }
-  // Reuse the rest of the code in the strlcpy() interceptor
-  return WRAP(strlcpy)(dst + len, src, size - len) + len;
+  if (src) {
+    srclen = internal_strlen(src);
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, src, srclen + 1);
+  }
+  if (dst && src && len < size)
+    COMMON_INTERCEPTOR_COPY_STRING(ctx, dst + len, src,
+                                   Min(srclen, size - len - 1));
+  return REAL(strlcat)(dst, src, size);
 }
 #define INIT_STRLCPY \
   COMMON_INTERCEPT_FUNCTION(strlcpy); \
diff --git a/compiler-rt/test/msan/Linux/strlcpy_strlcat.c 
b/compiler-rt/test/msan/Linux/strlcpy_strlcat.c
index 4b1a8f14fe7a9..3965e13f899d8 100644
--- a/compiler-rt/test/msan/Linux/strlcpy_strlcat.c
+++ b/compiler-rt/test/msan/Linux/strlcpy_strlcat.c
@@ -2,6 +2,7 @@
 // RUN: %clang_msan %s -o %t
 // RUN: %run %t
 // RUN: not %run %t uninit 2>&1 | FileCheck %s
+// RUN: not %run %t uninit_cat 2>&1 | FileCheck %s --check-prefix=CHECK-CAT
 
 #include <assert.h>
 #include <sanitizer/msan_interface.h>
@@ -13,10 +14,13 @@ static size_t (*volatile call_strlcat)(char *, const char 
*, size_t) = strlcat;
 int main(int argc, char **argv) {
   if (argc > 1) {
     char src[8] = "hello";
-    char dst[16];
+    char dst[16] = "ab";
 
     __msan_poison(src + 2, 1);
-    call_strlcpy(dst, src, sizeof(dst));
+    if (strcmp(argv[1], "uninit_cat") == 0)
+      call_strlcat(dst, src, sizeof(dst));
+    else
+      call_strlcpy(dst, src, sizeof(dst));
     return 0;
   }
 
@@ -58,3 +62,4 @@ int main(int argc, char **argv) {
 }
 
 // CHECK: Uninitialized bytes in strlcpy at offset 2 inside
+// CHECK-CAT: Uninitialized bytes in strlcat at offset 2 inside
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/strlcpy_oob.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/strlcpy_oob.cpp
index dbe5191fd42ea..11534db7c9935 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/strlcpy_oob.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/strlcpy_oob.cpp
@@ -1,6 +1,8 @@
 // RUN: %clangxx -O0 -g %s -o %t
 // RUN: not %run %t src_zero 2>&1 | FileCheck %s --check-prefix=SRC-ZERO
 // RUN: not %run %t src_small 2>&1 | FileCheck %s --check-prefix=SRC-SMALL
+// RUN: not %run %t cat_src_zero 2>&1 | FileCheck %s 
--check-prefix=CAT-SRC-ZERO
+// RUN: not %run %t cat_src_small 2>&1 | FileCheck %s 
--check-prefix=CAT-SRC-SMALL
 
 // REQUIRES: asan || msan
 // UNSUPPORTED: target={{.*linux.*}} && !glibc-2.38, target={{.*solaris.*}}
@@ -27,5 +29,15 @@ int main(int argc, char **argv) {
     // SRC-SMALL: SUMMARY: {{Address|Memory}}Sanitizer:
     return strlcpy(dst, src, 2) == 99;
   }
+  if (strcmp(argv[1], "cat_src_zero") == 0) {
+    // CAT-SRC-ZERO: {{(#0 .* in (wrap_|___interceptor_)?|Uninitialized bytes 
in )}}strlcat
+    // CAT-SRC-ZERO: SUMMARY: {{Address|Memory}}Sanitizer:
+    return strlcat(dst, src, 0) == 99;
+  }
+  if (strcmp(argv[1], "cat_src_small") == 0) {
+    // CAT-SRC-SMALL: {{(#0 .* in (wrap_|___interceptor_)?|Uninitialized bytes 
in )}}strlcat
+    // CAT-SRC-SMALL: SUMMARY: {{Address|Memory}}Sanitizer:
+    return strlcat(dst, src, 2) == 99;
+  }
   return 1;
 }

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to