[libc-commits] [libc] [libc] fix oob and overflow bugs in wcslcat and wcsncat (PR #203697)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Mon Jun 15 02:29:00 PDT 2026


================
@@ -21,6 +21,8 @@ LLVM_LIBC_FUNCTION(size_t, wcslcat,
                     size_t dstsize)) {
   const size_t dstlen = internal::string_length(dst);
   const size_t srclen = internal::string_length(src);
+  if (dstlen >= dstsize) 
+    return dstsize + srclen;
   int limit = static_cast<int>(dstsize - dstlen - 1);
   size_t returnval = (dstsize < dstlen ? dstsize : dstlen) + srclen;
----------------
kaladron wrote:

Your size check earlier can simplify this line because of the guarantee.

https://github.com/llvm/llvm-project/pull/203697


More information about the libc-commits mailing list