[PATCH] D42061: Add new interceptors: strlcpy(3) and strlcat(3)

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 14:10:57 PST 2018


vitalybuka added inline comments.


================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:6618
+    SIZE_T len = REAL(strnlen)(src, size);
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, src, len >= size ? size : len + 1);
+  }
----------------
krytarowski wrote:
> vitalybuka wrote:
> > from doc 
> > > Also note that strlcpy() and strlcat() only operate on  true ``C'' strings.
> > so we need COMMON_INTERCEPTOR_READ_STRING to enable strict_string_checks
> > 
> > len can't be len > size, so 
> > 
> > ```
> > if len < size
> >   we need to read len + 1
> > if len == size
> >   we need to read len  or size
> > ```
> > 
> > this probably should be
> > COMMON_INTERCEPTOR_READ_STRING(ctx, src, MIN(REAL(strnlen)(src, size), size - 1) + 1)
> "len can't be len > size, so" I don't see this enforced in the specification of the function.
from man strnlen:


> The  strnlen()  function  returns  the  number  of  characters in the string pointed to by s, excluding the terminating null byte   ('\0'), **but at most maxlen.**




================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:6744
+  COMMON_INTERCEPTOR_ENTER(ctx, strlcat, dst, src, size);
+  if (src) {
+    SIZE_T len = REAL(strnlen)(src, size);
----------------
can you remove if (src) branch? it's should be checked by WRAP(strlcpy)


Repository:
  rL LLVM

https://reviews.llvm.org/D42061





More information about the llvm-commits mailing list