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