From: Andrew Bartlett Date: Thu, 20 Apr 2017 02:00:21 +0000 (+1200) Subject: getncchanges: Do not segfault if somehow we get 0 results from an ldb_search with... X-Git-Tag: talloc-2.1.10~7 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=4031b303e495210ee8d6a4e2dd49974d90f9c402;p=samba.git getncchanges: Do not segfault if somehow we get 0 results from an ldb_search with scope BASE 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 Reviewed-by: Garming Sam --- diff --git a/source4/rpc_server/drsuapi/getncchanges.c b/source4/rpc_server/drsuapi/getncchanges.c index da294a6623a..a2063aaac8f 100644 --- a/source4/rpc_server/drsuapi/getncchanges.c +++ b/source4/rpc_server/drsuapi/getncchanges.c @@ -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]; /*