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
This commit is contained in:
Robert Fairley 2018-08-17 16:57:50 -04:00 committed by Atomic Bot
parent 8c301401af
commit 81889a0a35

View File

@ -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++)
{