getncchanges: Do not segfault if somehow we get 0 results from an ldb_search with...
[sfrench/samba-autobuild/.git] / 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];
 
                /*