From 81889a0a35c664bc7a07f6bc517865756495a114 Mon Sep 17 00:00:00 2001 From: Robert Fairley Date: Fri, 17 Aug 2018 16:57:50 -0400 Subject: [PATCH] libpriv/rpmostree-util: Handle NULL passed to rpm_str_ptrarray_contains This treats strs=NULL as an empty array and returns FALSE on the basis that a string (str) is not contained in an empty array. If str == NULL, then a run-time assertion will fail. Previously, a segmentation fault occured when NULL was dereferenced, expecting NULL to be handled by rpm_str_ptrarray_contains. fixes #1494 Closes: #1507 Approved by: jlebon --- src/libpriv/rpmostree-util.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libpriv/rpmostree-util.c b/src/libpriv/rpmostree-util.c index 5ac84175..45207288 100644 --- a/src/libpriv/rpmostree-util.c +++ b/src/libpriv/rpmostree-util.c @@ -456,11 +456,20 @@ rpmostree_str_has_prefix_in_ptrarray (const char *str, return rpmostree_str_has_prefix_in_strv (str, (char**)prefixes->pdata, prefixes->len); } -/* Like g_strv_contains() but for ptrarray */ +/** + * rpmostree_str_ptrarray_contains: + * + * Like g_strv_contains() but for ptrarray. + * Handles strs==NULL as an empty array. + */ gboolean rpmostree_str_ptrarray_contains (GPtrArray *strs, const char *str) { + g_assert (str); + if (!strs) + return FALSE; + guint n = strs->len; for (guint i = 0; i < n; i++) {