From: Pierre Schweitzer Subject: [PATCH] mpr: properly handle the count set to -1 when enumerating connections. Message-Id: Date: Fri, 23 Jun 2017 14:04:50 +0200 Hi, Please find attached a patch that solves a bug in MPR when enumerating active connections with several providers and several connections. In the specific case where the caller wants all the connections (providing a -1 count), that count was improperly handled and even though all the providers were filling the buffer, an incorrect count was returned to the caller. This is what that patch fixes. I've been testing it with ReactOS. And because sometimes pictures are better than words: https://www.heisspiter.net/~Pierre/rostests/NFS_VBSF_net_use.png Cheers, -- Pierre Schweitzer System & Network Administrator Senior Kernel Developer ReactOS Deutschland e.V. From 44d699b8e22ba4b0b121025bf7e166965a6a8f92 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Fri, 23 Jun 2017 13:53:43 +0200 Subject: [PATCH] mpr: properly handle the count set to -1 when enumerating connections. Signed-off-by: Pierre Schweitzer --- dlls/mpr/wnet.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dlls/mpr/wnet.c b/dlls/mpr/wnet.c index cbbc1bd..abade95 100644 --- a/dlls/mpr/wnet.c +++ b/dlls/mpr/wnet.c @@ -1266,7 +1266,7 @@ static DWORD _copyStringToEnumW(const WCHAR *source, DWORD* left, void** end) static DWORD _enumerateConnectedW(PWNetEnumerator enumerator, DWORD* user_count, void* user_buffer, DWORD* user_size) { - DWORD ret, index, count, size, i, left; + DWORD ret, index, count, total_count, size, i, left; void* end; NETRESOURCEW* curr, * buffer; HANDLE* handles; @@ -1290,6 +1290,7 @@ static DWORD _enumerateConnectedW(PWNetEnumerator enumerator, DWORD* user_count, curr = user_buffer; end = (char *)user_buffer + size; count = *user_count; + total_count = 0; ret = WN_NO_MORE_ENTRIES; for (index = 0; index < providerTable->numProviders; index++) @@ -1309,6 +1310,7 @@ static DWORD _enumerateConnectedW(PWNetEnumerator enumerator, DWORD* user_count, ret = providerTable->table[index].enumResource(handles[index], &count, buffer, &size); + total_count += count; if (ret == WN_MORE_DATA) break; @@ -1343,19 +1345,22 @@ static DWORD _enumerateConnectedW(PWNetEnumerator enumerator, DWORD* user_count, ++curr; } - count = *user_count - count; + if (*user_count != -1) + count = *user_count - total_count; + else + count = *user_count; size = left; } - if (ret != WN_SUCCESS || count == 0) + if (ret != WN_SUCCESS || total_count == 0) break; } } - if (count == 0) + if (total_count == 0) ret = WN_NO_MORE_ENTRIES; - *user_count = *user_count - count; + *user_count = total_count; if (ret != WN_MORE_DATA && ret != WN_NO_MORE_ENTRIES) ret = WN_SUCCESS; -- 2.7.4