Blame SOURCES/0002-PROXY-Return-data-in-output-parameter-if-everything-.patch

d6181b
From 59c0d659fc71b47278c2faadaa844e8516454626 Mon Sep 17 00:00:00 2001
d6181b
From: Lukas Slebodnik <lslebodn@redhat.com>
d6181b
Date: Fri, 28 Jun 2019 16:27:21 +0200
d6181b
Subject: [PATCH 2/2] PROXY: Return data in output parameter if everything is
d6181b
 OK
d6181b
d6181b
The function remove_duplicate_group_members might return EOK also in the middle
d6181b
of function but return parameter was not set with right data.
d6181b
Processing continued in the function save_group but there was a
d6181b
dereference of NULL pointer.
d6181b
d6181b
Introduced in: https://pagure.io/SSSD/sssd/issue/3931
d6181b
d6181b
Crash:
d6181b
  (gdb) bt
d6181b
  #0  0x00007fb4ce4a9ac5 in save_group (sysdb=sysdb@entry=0x55c9a0efb230, dom=dom@entry=0x55c9a0efb420, grp=grp@entry=0x55c9a0f370f0, real_name=0x55c9a0f47340 "nobody@ldap",
d6181b
      alias=alias@entry=0x0) at src/providers/proxy/proxy_id.c:748
d6181b
  #1  0x00007fb4ce4aa600 in get_gr_gid (mem_ctx=mem_ctx@entry=0x55c9a0f38be0, sysdb=sysdb@entry=0x55c9a0efb230, dom=dom@entry=0x55c9a0efb420, gid=99, now=<optimized out>,
d6181b
      ctx=<optimized out>) at src/providers/proxy/proxy_id.c:1160
d6181b
  #2  0x00007fb4ce4ac9e5 in get_initgr_groups_process (pwd=0x55c9a0f384a0, pwd=0x55c9a0f384a0, dom=0x55c9a0efb420, sysdb=0x55c9a0efb230, ctx=0x55c9a0f048e0, memctx=0x55c9a0f38be0)
d6181b
      at src/providers/proxy/proxy_id.c:1553
d6181b
  #3  get_initgr (i_name=<optimized out>, dom=0x55c9a0efb420, sysdb=<optimized out>, ctx=0x55c9a0f048e0, mem_ctx=0x55c9a0f38b70) at src/providers/proxy/proxy_id.c:1461
d6181b
  #4  proxy_account_info (domain=0x55c9a0efb420, be_ctx=<optimized out>, data=<optimized out>, ctx=0x55c9a0f048e0, mem_ctx=0x55c9a0f38b70) at src/providers/proxy/proxy_id.c:1659
d6181b
  #5  proxy_account_info_handler_send (mem_ctx=<optimized out>, id_ctx=0x55c9a0f048e0, data=<optimized out>, params=0x55c9a0f39790) at src/providers/proxy/proxy_id.c:1758
d6181b
  #6  0x000055c99fc67677 in file_dp_request (_dp_req=<synthetic pointer>, req=0x55c9a0f39470, request_data=<optimized out>, dp_flags=1, method=DPM_ACCOUNT_HANDLER, target=DPT_ID,
d6181b
      name=<optimized out>, domainname=0x55c9a0f39190 "LDAP", provider=0x55c9a0efe0e0, mem_ctx=<optimized out>) at src/providers/data_provider/dp_request.c:250
d6181b
  #7  dp_req_send (mem_ctx=0x55c9a0f37b60, provider=provider@entry=0x55c9a0efe0e0, domain=domain@entry=0x55c9a0f39190 "LDAP", name=<optimized out>, target=target@entry=DPT_ID,
d6181b
      method=method@entry=DPM_ACCOUNT_HANDLER, dp_flags=dp_flags@entry=1, request_data=0x55c9a0f37c00, _request_name=0x55c9a0f37b60) at src/providers/data_provider/dp_request.c:295
d6181b
  #8  0x000055c99fc6a132 in dp_get_account_info_send (mem_ctx=<optimized out>, ev=0x55c9a0eddbc0, sbus_req=<optimized out>, provider=0x55c9a0efe0e0, dp_flags=1,
d6181b
      entry_type=<optimized out>, filter=0x55c9a0f358d0 "name=nobody@ldap", domain=0x55c9a0f39190 "LDAP", extra=0x55c9a0f354a0 "") at src/providers/data_provider/dp_target_id.c:528
d6181b
  #9  0x00007fb4da35265b in _sbus_sss_invoke_in_uusss_out_qus_step (ev=0x55c9a0eddbc0, te=<optimized out>, tv=..., private_data=<optimized out>) at src/sss_iface/sbus_sss_invokers.c:2847
d6181b
  #10 0x00007fb4d9cfb1cf in tevent_common_invoke_timer_handler () from /lib64/libtevent.so.0
d6181b
  #11 0x00007fb4d9cfb339 in tevent_common_loop_timer_delay () from /lib64/libtevent.so.0
d6181b
  #12 0x00007fb4d9cfc2f9 in epoll_event_loop_once () from /lib64/libtevent.so.0
d6181b
  #13 0x00007fb4d9cfa7b7 in std_event_loop_once () from /lib64/libtevent.so.0
d6181b
  #14 0x00007fb4d9cf5b5d in _tevent_loop_once () from /lib64/libtevent.so.0
d6181b
  #15 0x00007fb4d9cf5d8b in tevent_common_loop_wait () from /lib64/libtevent.so.0
d6181b
  #16 0x00007fb4d9cfa757 in std_event_loop_wait () from /lib64/libtevent.so.0
d6181b
  #17 0x00007fb4dd955ac3 in server_loop (main_ctx=0x55c9a0edf090) at src/util/server.c:724
d6181b
  #18 0x000055c99fc59760 in main (argc=8, argv=<optimized out>) at src/providers/data_provider_be.c:747
d6181b
  (gdb) l
d6181b
  (gdb) bt
d6181b
  #0  0x00007fb4ce4a9ac5 in save_group (sysdb=sysdb@entry=0x55c9a0efb230, dom=dom@entry=0x55c9a0efb420, grp=grp@entry=0x55c9a0f370f0, real_name=0x55c9a0f47340 "nobody@ldap",
d6181b
      alias=alias@entry=0x0) at src/providers/proxy/proxy_id.c:748
d6181b
  #1  0x00007fb4ce4aa600 in get_gr_gid (mem_ctx=mem_ctx@entry=0x55c9a0f38be0, sysdb=sysdb@entry=0x55c9a0efb230, dom=dom@entry=0x55c9a0efb420, gid=99, now=<optimized out>,
d6181b
      ctx=<optimized out>) at src/providers/proxy/proxy_id.c:1160
d6181b
  #2  0x00007fb4ce4ac9e5 in get_initgr_groups_process (pwd=0x55c9a0f384a0, pwd=0x55c9a0f384a0, dom=0x55c9a0efb420, sysdb=0x55c9a0efb230, ctx=0x55c9a0f048e0, memctx=0x55c9a0f38be0)
d6181b
      at src/providers/proxy/proxy_id.c:1553
d6181b
  #3  get_initgr (i_name=<optimized out>, dom=0x55c9a0efb420, sysdb=<optimized out>, ctx=0x55c9a0f048e0, mem_ctx=0x55c9a0f38b70) at src/providers/proxy/proxy_id.c:1461
d6181b
  #4  proxy_account_info (domain=0x55c9a0efb420, be_ctx=<optimized out>, data=<optimized out>, ctx=0x55c9a0f048e0, mem_ctx=0x55c9a0f38b70) at src/providers/proxy/proxy_id.c:1659
d6181b
  #5  proxy_account_info_handler_send (mem_ctx=<optimized out>, id_ctx=0x55c9a0f048e0, data=<optimized out>, params=0x55c9a0f39790) at src/providers/proxy/proxy_id.c:1758
d6181b
  #6  0x000055c99fc67677 in file_dp_request (_dp_req=<synthetic pointer>, req=0x55c9a0f39470, request_data=<optimized out>, dp_flags=1, method=DPM_ACCOUNT_HANDLER, target=DPT_ID,
d6181b
      name=<optimized out>, domainname=0x55c9a0f39190 "LDAP", provider=0x55c9a0efe0e0, mem_ctx=<optimized out>) at src/providers/data_provider/dp_request.c:250
d6181b
  #7  dp_req_send (mem_ctx=0x55c9a0f37b60, provider=provider@entry=0x55c9a0efe0e0, domain=domain@entry=0x55c9a0f39190 "LDAP", name=<optimized out>, target=target@entry=DPT_ID,
d6181b
      method=method@entry=DPM_ACCOUNT_HANDLER, dp_flags=dp_flags@entry=1, request_data=0x55c9a0f37c00, _request_name=0x55c9a0f37b60) at src/providers/data_provider/dp_request.c:295
d6181b
  #8  0x000055c99fc6a132 in dp_get_account_info_send (mem_ctx=<optimized out>, ev=0x55c9a0eddbc0, sbus_req=<optimized out>, provider=0x55c9a0efe0e0, dp_flags=1,
d6181b
      entry_type=<optimized out>, filter=0x55c9a0f358d0 "name=nobody@ldap", domain=0x55c9a0f39190 "LDAP", extra=0x55c9a0f354a0 "") at src/providers/data_provider/dp_target_id.c:528
d6181b
  #9  0x00007fb4da35265b in _sbus_sss_invoke_in_uusss_out_qus_step (ev=0x55c9a0eddbc0, te=<optimized out>, tv=..., private_data=<optimized out>) at src/sss_iface/sbus_sss_invokers.c:2847
d6181b
  #10 0x00007fb4d9cfb1cf in tevent_common_invoke_timer_handler () from /lib64/libtevent.so.0
d6181b
  #11 0x00007fb4d9cfb339 in tevent_common_loop_timer_delay () from /lib64/libtevent.so.0
d6181b
  #12 0x00007fb4d9cfc2f9 in epoll_event_loop_once () from /lib64/libtevent.so.0
d6181b
  #13 0x00007fb4d9cfa7b7 in std_event_loop_once () from /lib64/libtevent.so.0
d6181b
  #14 0x00007fb4d9cf5b5d in _tevent_loop_once () from /lib64/libtevent.so.0
d6181b
  #15 0x00007fb4d9cf5d8b in tevent_common_loop_wait () from /lib64/libtevent.so.0
d6181b
  #16 0x00007fb4d9cfa757 in std_event_loop_wait () from /lib64/libtevent.so.0
d6181b
  #17 0x00007fb4dd955ac3 in server_loop (main_ctx=0x55c9a0edf090) at src/util/server.c:724
d6181b
  #18 0x000055c99fc59760 in main (argc=8, argv=<optimized out>) at src/providers/data_provider_be.c:747
d6181b
  (gdb) l
d6181b
  733         ret = remove_duplicate_group_members(tmp_ctx, grp, &ngroup);
d6181b
  734         if (ret != EOK) {
d6181b
  735             DEBUG(SSSDBG_CRIT_FAILURE, "Failed to remove duplicate group member     s\n");
d6181b
  736             goto done;
d6181b
  737         }
d6181b
  738
d6181b
  739         DEBUG_GR_MEM(SSSDBG_TRACE_LIBS, ngroup);
d6181b
  740
d6181b
  741         ret = sysdb_transaction_start(sysdb);
d6181b
  742         if (ret != EOK) {
d6181b
  743             DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
d6181b
  744             goto done;
d6181b
  745         }
d6181b
  746         in_transaction = true;
d6181b
  747
d6181b
  748         if (ngroup->gr_mem && ngroup->gr_mem[0]) {
d6181b
  749             attrs = sysdb_new_attrs(tmp_ctx);
d6181b
  750             if (!attrs) {
d6181b
  751                 DEBUG(SSSDBG_CRIT_FAILURE, "Allocation error?!\n");
d6181b
  752                 ret = ENOMEM;
d6181b
  (gdb) p ngroup
d6181b
  $1 = (struct group *) 0x0
d6181b
  743             DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
d6181b
  744             goto done;
d6181b
  745         }
d6181b
  746         in_transaction = true;
d6181b
  747
d6181b
  748         if (ngroup->gr_mem && ngroup->gr_mem[0]) {
d6181b
  749             attrs = sysdb_new_attrs(tmp_ctx);
d6181b
  750             if (!attrs) {
d6181b
  751                 DEBUG(SSSDBG_CRIT_FAILURE, "Allocation error?!\n");
d6181b
  752                 ret = ENOMEM;
d6181b
  (gdb) p ngroup
d6181b
  $1 = (struct group *) 0x0
d6181b
d6181b
Merges: https://pagure.io/SSSD/sssd/pull-request/4036
d6181b
d6181b
Resolves:
d6181b
https://pagure.io/SSSD/sssd/issue/4037
d6181b
d6181b
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
d6181b
(cherry picked from commit e1b678c0cce73494d986610920b03956c1dbb62a)
d6181b
---
d6181b
 src/providers/proxy/proxy_id.c | 4 +++-
d6181b
 1 file changed, 3 insertions(+), 1 deletion(-)
d6181b
d6181b
diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
d6181b
index e1be29076..91105ce5a 100644
d6181b
--- a/src/providers/proxy/proxy_id.c
d6181b
+++ b/src/providers/proxy/proxy_id.c
d6181b
@@ -698,10 +698,12 @@ static errno_t remove_duplicate_group_members(TALLOC_CTX *mem_ctx,
d6181b
     }
d6181b
     grp->gr_mem[i] = NULL;
d6181b
 
d6181b
-    *_grp = talloc_steal(mem_ctx, grp);
d6181b
     ret = EOK;
d6181b
 
d6181b
 done:
d6181b
+    if (ret == EOK) {
d6181b
+        *_grp = talloc_steal(mem_ctx, grp);
d6181b
+    }
d6181b
     talloc_zfree(tmp_ctx);
d6181b
 
d6181b
     return ret;
d6181b
-- 
d6181b
2.20.1
d6181b