summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-07-02 15:15:17 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2021-07-02 22:32:19 +0100
commit107e21635bb59a01bc92dda05211b03a7d40bde6 (patch)
treee7a01e985f6db54cb29ece5ca357dcca626b4645
parentf127fed75d3bae3a1eb0be6feea334bb8d1c3a43 (diff)
downloadsystemd-107e21635bb59a01bc92dda05211b03a7d40bde6.tar.gz
hashmap: make sure hashmap_get_strv()+set_get_strv() work with a NULL object
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.
-rw-r--r--src/basic/hashmap.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 9ed69bd3d2..0decbb04e1 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -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;