]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
add sanity check in tor_memmem
authortrinity-1686a <trinity@deuxfleurs.fr>
Wed, 15 Nov 2023 01:01:34 +0000 (02:01 +0100)
committertrinity-1686a <trinity@deuxfleurs.fr>
Wed, 15 Nov 2023 01:01:34 +0000 (02:01 +0100)
it's believed most libc already have those, but just in case, it can't
hurt

src/lib/string/util_string.c

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