--- source3/passdb/lookup_sid.c.ORIG 2021-01-26 16:25:59.235435000 +0100 +++ source3/passdb/lookup_sid.c 2021-01-27 13:54:44.541256000 +0100 @@ -1247,7 +1247,7 @@ { struct wbcDomainSid *wbc_sids = NULL; struct wbcUnixId *wbc_ids = NULL; - uint32_t i, num_not_cached; + uint32_t i, num_not_cached, num_not_cached_size; wbcErr err; bool ret = false; @@ -1277,7 +1277,8 @@ if (idmap_cache_find_sid2unixid(&sids[i], &ids[i], &expired) && !expired) { - continue; + if (ids[i].type != ID_TYPE_NOT_SPECIFIED) + continue; } ids[i].type = ID_TYPE_NOT_SPECIFIED; memcpy(&wbc_sids[num_not_cached], &sids[i], @@ -1300,10 +1301,16 @@ wbcErrorString(err))); } + num_not_cached_size = num_not_cached; num_not_cached = 0; for (i=0; i= num_not_cached_size) { + DEBUG(0, ("Internal Error: num_not_cached(%d) >= num_not_cached_size(%d), i=%d, num_sids=%d\n", + num_not_cached, num_not_cached_size, i, num_sids)); + goto fail; + } switch (wbc_ids[num_not_cached].type) { case WBC_ID_TYPE_UID: ids[i].type = ID_TYPE_UID;