From: Bruno Haible Date: Tue, 10 Sep 2024 00:07:57 +0000 (+0200) Subject: string-desc: Fix undefined behaviour. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5423d6831e6bbcb21eab3f01bef304a3b98e88ea;p=gnulib.git string-desc: Fix undefined behaviour. * lib/string-desc-contains.c (string_desc_contains): Handle the case of an empty haystack before invoking 'memmem'. --- diff --git a/ChangeLog b/ChangeLog index d3731a561d..756ae71eea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-09-09 Bruno Haible + + string-desc: Fix undefined behaviour. + * lib/string-desc-contains.c (string_desc_contains): Handle the case of + an empty haystack before invoking 'memmem'. + 2024-09-09 Bruno Haible striconv, striconveh, unicodeio: Drop workaround for glibc 2.1. diff --git a/lib/string-desc-contains.c b/lib/string-desc-contains.c index 21c52069f6..ec79d6acf0 100644 --- a/lib/string-desc-contains.c +++ b/lib/string-desc-contains.c @@ -35,6 +35,8 @@ string_desc_contains (string_desc_t haystack, string_desc_t needle) { if (needle._nbytes == 0) return 0; + if (haystack._nbytes == 0) + return -1; void *found = memmem (haystack._data, haystack._nbytes, needle._data, needle._nbytes); if (found != NULL)