[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:30:18 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:
> > 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.**
> > 
> > 
> I've misunderstood the proposal. I will go for it.
> 
> Is there a macro for `MIN()` or should I define one?
It's actually Min(). 
It's defined compiler-rt/lib/sanitizer_common/sanitizer_common.h and already used in this file. E.g. INTERCEPTOR(SIZE_T, strnlen


Repository:
  rL LLVM

https://reviews.llvm.org/D42061





More information about the llvm-commits mailing list