]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
Allow memstr() to be called with NULL arguments
authorTobias Brunner <tobias@strongswan.org>
Thu, 28 Mar 2013 13:12:53 +0000 (14:12 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:03:12 +0000 (11:03 +0200)
src/libstrongswan/utils/utils.c

index ba32720ea2e7895d09c6f9cd45c7bbde28cc0b5c..aa59f4a4dc19de9b8810527995e0641ecfea03eb 100644 (file)
@@ -102,7 +102,12 @@ void memwipe_noinline(void *ptr, size_t n)
 void *memstr(const void *haystack, const char *needle, size_t n)
 {
        unsigned const char *pos = haystack;
-       size_t l = strlen(needle);
+       size_t l;
+
+       if (!haystack || !needle || (l = strlen(needle)) == 0)
+       {
+               return NULL;
+       }
        for (; n >= l; ++pos, --n)
        {
                if (memeq(pos, needle, l))