getncchanges: Do not segfault if somehow we get 0 results from an ldb_search with...
authorAndrew Bartlett <abartlet@samba.org>
Thu, 20 Apr 2017 02:00:21 +0000 (14:00 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 21 Jul 2017 07:30:25 +0000 (09:30 +0200)
This should not happen, but we have seen this happen in autobuild
before the whole-DB locking issues were resolved by
https://bugzilla.samba.org/show_bug.cgi?id=12858

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/rpc_server/drsuapi/getncchanges.c

index da294a6623aa2926f36506e28f3117e7292dd534..a2063aaac8fe84d7ef302e9b9be89a127799bca8 100644 (file)
@@ -2578,8 +2578,13 @@ allowed:
                W_ERROR_HAVE_NO_MEMORY(msg_dn);
 
 
-               /* by re-searching here we avoid having a lot of full
-                * records in memory between calls to getncchanges
+               /*
+                * by re-searching here we avoid having a lot of full
+                * records in memory between calls to getncchanges.
+                *
+                * We expect that we may get some objects that vanish
+                * (tombstone expunge) between the first and second
+                * check.
                 */
                ret = drsuapi_search_with_extended_dn(sam_ctx, obj, &msg_res,
                                                      msg_dn,
@@ -2593,6 +2598,16 @@ allowed:
                        continue;
                }
 
+               if (msg_res->count == 0) {
+                       DEBUG(1,("getncchanges: got LDB_SUCCESS but failed"
+                                "to get any results in fetch of DN "
+                                "%s (race with tombstone expunge?)\n",
+                                ldb_dn_get_extended_linearized(obj,
+                                                               msg_dn, 1)));
+                       talloc_free(obj);
+                       continue;
+               }
+
                msg = msg_res->msgs[0];
 
                /*