From 6c10d9b60de07759cf3e6de8dc41dc0b95970e37 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 10 Sep 2024 02:07:57 +0200 Subject: [PATCH] string-desc: Fix undefined behaviour. * lib/string-desc-contains.c (string_desc_contains): Handle the case of an empty haystack before invoking 'memmem'. --- ChangeLog | 6 ++++++ lib/string-desc-contains.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index fa48d7a5bd..9b25a979bd 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-05 Paul Eggert Fix COPYING.EXCEPTION license notices 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) -- 2.39.5