From abc2d4d2284b78d1c71a1c26832aad4044300be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 5 Mar 2017 00:24:08 +0000 Subject: [PATCH] [WS2_32]: Fix the crash in ws2_32 reported in CORE-12852, that happens when opening e.g. Word 2010 for the first time (when it asks for registration): - Check whether WsNcLoadProvider really succeeded in loading a provider in WsNcGetCatalogFromProviderId, and return appropriate error code. - In WsNqLookupServiceBegin, initialize CatalogEntry to NULL prior to calling WsNcGetCatalogFromProviderId, and check for success or failure of WsNqAddProvider (and fail in accordance). svn path=/trunk/; revision=74067 --- reactos/dll/win32/ws2_32/src/nscatalo.c | 26 ++++++++++++------------- reactos/dll/win32/ws2_32/src/nsquery.c | 11 +++++++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/reactos/dll/win32/ws2_32/src/nscatalo.c b/reactos/dll/win32/ws2_32/src/nscatalo.c index d98c4c88981..43a782a058a 100644 --- a/reactos/dll/win32/ws2_32/src/nscatalo.c +++ b/reactos/dll/win32/ws2_32/src/nscatalo.c @@ -497,6 +497,7 @@ WsNcGetCatalogFromProviderId(IN PNSCATALOG Catalog, IN LPGUID ProviderId, OUT PNSCATALOG_ENTRY *CatalogEntry) { + INT ErrorCode = WSAEINVAL; PLIST_ENTRY NextEntry; PNSCATALOG_ENTRY Entry; @@ -514,25 +515,24 @@ WsNcGetCatalogFromProviderId(IN PNSCATALOG Catalog, /* Check if this is the Catalog Entry ID we want */ if (IsEqualGUID(&Entry->ProviderId, ProviderId)) { - /* Check if it doesn't already have a provider */ + /* If it doesn't already have a provider, load the provider */ if (!Entry->Provider) - { - /* Match, load the Provider */ - WsNcLoadProvider(Catalog, Entry); - } + ErrorCode = WsNcLoadProvider(Catalog, Entry); - /* Reference the entry and return it */ - InterlockedIncrement(&Entry->RefCount); - *CatalogEntry = Entry; - break; + /* If we succeeded, reference the entry and return it */ + if (Entry->Provider /* || ErrorCode == ERROR_SUCCESS */) + { + InterlockedIncrement(&Entry->RefCount); + *CatalogEntry = Entry; + ErrorCode = ERROR_SUCCESS; + break; + } } } - /* Release the catalog */ + /* Release the lock and return */ WsNcUnlock(); - - /* Return */ - return ERROR_SUCCESS; + return ErrorCode; } BOOL diff --git a/reactos/dll/win32/ws2_32/src/nsquery.c b/reactos/dll/win32/ws2_32/src/nsquery.c index ca39659e07d..eb476aeffd5 100644 --- a/reactos/dll/win32/ws2_32/src/nsquery.c +++ b/reactos/dll/win32/ws2_32/src/nsquery.c @@ -355,7 +355,7 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery, PLIST_ENTRY Entry; INT ErrorCode; DWORD ClassInfoSize; - PNSCATALOG_ENTRY CatalogEntry; + PNSCATALOG_ENTRY CatalogEntry = NULL; ENUM_CONTEXT EnumContext; BOOLEAN TryAgain; @@ -396,10 +396,13 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery, ErrorCode = SOCKET_ERROR; goto Exit; } - else + /* We succeeded, add this provider */ + else if (!WsNqAddProvider(NsQuery, CatalogEntry->Provider)) { - /* Add this provider */ - WsNqAddProvider(NsQuery, CatalogEntry->Provider); + /* Fail */ + SetLastError(WSA_NOT_ENOUGH_MEMORY); + ErrorCode = SOCKET_ERROR; + goto Exit; } } else