Blame SOURCES/0001-SYSDB-merge_res_sysdb_attrs-fixed-to-avoid-NULL-ptr-.patch

bac598
From ff24d1538af88f83d0a3cc2817952cf70e7ca580 Mon Sep 17 00:00:00 2001
bac598
From: Alexey Tikhonov <atikhono@redhat.com>
bac598
Date: Sun, 22 Nov 2020 17:44:07 +0100
bac598
Subject: [PATCH] SYSDB: merge_res_sysdb_attrs() fixed to avoid NULL ptr in
bac598
 msgs[]
bac598
MIME-Version: 1.0
bac598
Content-Type: text/plain; charset=UTF-8
bac598
Content-Transfer-Encoding: 8bit
bac598
bac598
This helps to avoid sssd_be segfaults at be_refresh_get_values_ex() due to NULL
bac598
ptrs in results of sysdb_search_with_ts_attr()
bac598
bac598
Resolves: https://github.com/SSSD/sssd/issues/5412
bac598
bac598
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bac598
---
bac598
 src/db/sysdb_search.c | 11 +++++++----
bac598
 1 file changed, 7 insertions(+), 4 deletions(-)
bac598
bac598
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
bac598
index e616fd5bc..4ff65c1ae 100644
bac598
--- a/src/db/sysdb_search.c
bac598
+++ b/src/db/sysdb_search.c
bac598
@@ -221,6 +221,7 @@ static errno_t merge_res_sysdb_attrs(TALLOC_CTX *mem_ctx,
bac598
                                      const char *attrs[])
bac598
 {
bac598
     errno_t ret;
bac598
+    size_t ts_cache_res_count = 0;
bac598
     struct ldb_result *ts_cache_res = NULL;
bac598
 
bac598
     if (ts_res == NULL || ctx->ldb_ts == NULL) {
bac598
@@ -231,7 +232,6 @@ static errno_t merge_res_sysdb_attrs(TALLOC_CTX *mem_ctx,
bac598
     if (ts_cache_res == NULL) {
bac598
         return ENOMEM;
bac598
     }
bac598
-    ts_cache_res->count = ts_res->count;
bac598
     ts_cache_res->msgs = talloc_zero_array(ts_cache_res,
bac598
                                            struct ldb_message *,
bac598
                                            ts_res->count);
bac598
@@ -244,15 +244,18 @@ static errno_t merge_res_sysdb_attrs(TALLOC_CTX *mem_ctx,
bac598
         ret = merge_msg_sysdb_attrs(ts_cache_res->msgs,
bac598
                                     ctx,
bac598
                                     ts_res->msgs[c],
bac598
-                                    &ts_cache_res->msgs[c], attrs);
bac598
-        if (ret != EOK) {
bac598
+                                    &ts_cache_res->msgs[ts_cache_res_count],
bac598
+                                    attrs);
bac598
+        if ((ret != EOK) || (ts_cache_res->msgs[ts_cache_res_count] == NULL)) {
bac598
             DEBUG(SSSDBG_MINOR_FAILURE,
bac598
                   "Cannot merge sysdb cache values for %s\n",
bac598
                   ldb_dn_get_linearized(ts_res->msgs[c]->dn));
bac598
-            /* non-fatal, we just get only the non-timestamp attrs */
bac598
+            /* non-fatal, just skip */
bac598
             continue;
bac598
         }
bac598
+        ts_cache_res_count += 1;
bac598
     }
bac598
+    ts_cache_res->count = ts_cache_res_count;
bac598
 
bac598
     *_ts_cache_res = ts_cache_res;
bac598
     return EOK;
bac598
-- 
bac598
2.21.3
bac598