From 7b91011d6edf2febbce28f3d73d149a7f0b81843 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 28 Mar 2013 14:12:53 +0100 Subject: [PATCH] Allow memstr() to be called with NULL arguments --- src/libstrongswan/utils/utils.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index ba32720ea..aa59f4a4d 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -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))