From 577d0600c48ca7da0fcd40d91789347dadfa070b Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 16 Apr 2025 12:43:05 +0200 Subject: [PATCH] util-strings: don't crash the Xserver on memory alloc failure It's only consumer already properly checking for NULL return value, so can directly use calloc() here, instead of zalloc() which is crashing the Xserver. Signed-off-by: Enrico Weigelt, metux IT consult --- src/util-strings.c | 4 +++- src/util-strings.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/util-strings.c b/src/util-strings.c index 249604b..7ad25ae 100644 --- a/src/util-strings.c +++ b/src/util-strings.c @@ -122,7 +122,9 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements) } size_t strv_len = nelems + 1; /* NULL-terminated */ - char **strv = zalloc(strv_len * sizeof *strv); + char **strv = calloc(strv_len, sizeof(*strv)); + if (!strv) + return NULL; size_t idx = 0; const char *word; diff --git a/src/util-strings.h b/src/util-strings.h index 47306b8..8d3979c 100644 --- a/src/util-strings.h +++ b/src/util-strings.h @@ -253,7 +253,10 @@ double_array_from_string(const char *in, if(!strv) return result; - double *numv = zalloc(sizeof(double) * nelem); + double *numv = calloc(nelem, sizeof(double)); + if (!numv) + goto out; + for (size_t idx = 0; idx < nelem; idx++) { double val; if (!safe_atod(strv[idx], &val))