Blob Blame History Raw
From 50fdc7f23f35744ffff1763fe2d804b18c1c5340 Mon Sep 17 00:00:00 2001
From: Michal Srb <michal@redhat.com>
Date: Tue, 7 Sep 2021 14:40:21 +0200
Subject: [PATCH] [rhbz] Be a little bit more defensive when working with
 subcomponents

Components in RHEL can have "subcomponents" in Bugzilla. Some of them
have, some of them don't. Better be careful.

See: rhbz#1998435

Signed-off-by: Michal Srb <michal@redhat.com>
---
 src/plugins/rhbz.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
index c2855a70..0dae1e93 100644
--- a/src/plugins/rhbz.c
+++ b/src/plugins/rhbz.c
@@ -1036,13 +1036,17 @@ char *rhbz_get_default_sub_component(const char *component, xmlrpc_value *sub_co
     }
     else
     {
-        xmlrpc_array_read_item(&env, sub_components, sc_array_size - 1, &sc_struct);
-        xmlrpc_struct_find_value(&env, sc_struct, "name", &sc_name);
-        xmlrpc_read_string(&env, sc_name, &sc_str_name);
-        if (sc_struct)
-            xmlrpc_DECREF(sc_struct);
-        if (sc_name)
-            xmlrpc_DECREF(sc_name);
+        if (sc_array_size) {
+            xmlrpc_array_read_item(&env, sub_components, sc_array_size - 1, &sc_struct);
+            if (xmlrpc_struct_has_key(&env, sc_struct, "name")) {
+                xmlrpc_struct_find_value(&env, sc_struct, "name", &sc_name);
+                xmlrpc_read_string(&env, sc_name, &sc_str_name);
+            }
+            if (sc_struct)
+                xmlrpc_DECREF(sc_struct);
+            if (sc_name)
+                xmlrpc_DECREF(sc_name);
+        }
     }
 
     return (char *)sc_str_name;
-- 
2.31.1