]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hashmap: make sure hashmap_get_strv()+set_get_strv() work with a NULL object
authorLennart Poettering <lennart@poettering.net>
Fri, 2 Jul 2021 13:15:17 +0000 (15:15 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 2 Jul 2021 21:32:19 +0000 (22:32 +0100)
Before we invoke n_entries() we need to check for non-NULL here, like in
all other calls to the helper function. Otherwise we'll crash when
invoked with a NULL object, which we usually consider equivalent to an
empty one though.

src/basic/hashmap.c

index 9ed69bd3d271ebc7eb09afdd25432d4886c6e20b..0decbb04e10fdba6e458b033c5f34044f8516fdb 100644 (file)
@@ -1761,6 +1761,9 @@ char** _hashmap_get_strv(HashmapBase *h) {
         Iterator i;
         unsigned idx, n;
 
+        if (!h)
+                return new0(char*, 1);
+
         sv = new(char*, n_entries(h)+1);
         if (!sv)
                 return NULL;