add sanity check in tor_memmem

it's believed most libc already have those, but just in case, it can't
hurt
This commit is contained in:
trinity-1686a 2023-11-15 02:01:34 +01:00
parent cec6f9919d
commit f2ddfdd50e

View File

@ -31,6 +31,8 @@ tor_memmem(const void *_haystack, size_t hlen,
{ {
#if defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2) #if defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2)
raw_assert(nlen); raw_assert(nlen);
if (nlen > hlen)
return NULL;
return memmem(_haystack, hlen, _needle, nlen); return memmem(_haystack, hlen, _needle, nlen);
#else #else
/* This isn't as fast as the GLIBC implementation, but it doesn't need to /* This isn't as fast as the GLIBC implementation, but it doesn't need to