From ff228503bf5135cbbbe9d713bad8129e30fad38f Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Tue, 9 Sep 2008 11:26:54 +0000 Subject: [PATCH] - Handle NULL pointer in INetCfgComponent::GetDisplayName and INetCfgComponent_GetHelpText - Initialize to zero NetCfgComponentItem - Dont fail if subkey is not a guid (required because ReactOS TCP/IP guid is not yet generated) - Fix enumeration of network components - Register CNetCfg class svn path=/trunk/; revision=36080 --- reactos/dll/win32/netcfgx/inetcfgcomp_iface.c | 28 ++++++++++++++--- reactos/dll/win32/netcfgx/netcfg_iface.c | 22 +++++-------- reactos/dll/win32/netcfgx/netcfgx.c | 31 +++++++++++++++++-- reactos/dll/win32/netcfgx/netcfgx.rbuild | 1 + reactos/dll/win32/netcfgx/precomp.h | 1 + reactos/dll/win32/netshell/lanconnectui.c | 21 +++++++------ 6 files changed, 73 insertions(+), 31 deletions(-) diff --git a/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c b/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c index 8ef1a9ec64e..6a72419c52e 100644 --- a/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c +++ b/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c @@ -69,16 +69,26 @@ INetCfgComponent_fnGetDisplayName( LPWSTR * ppszwDisplayName) { LPWSTR szName; + UINT Length; INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; if (This == NULL || ppszwDisplayName == NULL) return E_POINTER; - szName = CoTaskMemAlloc((wcslen(This->pItem->szDisplayName)+1) * sizeof(WCHAR)); + if (This->pItem->szDisplayName) + Length = wcslen(This->pItem->szDisplayName)+1; + else + Length = 1; + + szName = CoTaskMemAlloc(Length * sizeof(WCHAR)); if (!szName) return E_OUTOFMEMORY; - wcscpy(szName, This->pItem->szDisplayName); + if (Length > 1) + wcscpy(szName, This->pItem->szDisplayName); + else + szName[0] = L'\0'; + *ppszwDisplayName = szName; return S_OK; @@ -123,16 +133,26 @@ INetCfgComponent_fnGetHelpText( LPWSTR * ppszwHelpText) { LPWSTR szHelp; + UINT Length; INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; if (This == NULL || ppszwHelpText == NULL) return E_POINTER; - szHelp = CoTaskMemAlloc((wcslen(This->pItem->szHelpText)+1) * sizeof(WCHAR)); + if (This->pItem->szHelpText) + Length = wcslen(This->pItem->szHelpText)+1; + else + Length = 1; + + szHelp = CoTaskMemAlloc(Length * sizeof(WCHAR)); if (!szHelp) return E_OUTOFMEMORY; - wcscpy(szHelp, This->pItem->szHelpText); + if (Length > 1) + wcscpy(szHelp, This->pItem->szHelpText); + else + szHelp[0] = L'\0'; + *ppszwHelpText = szHelp; return S_OK; diff --git a/reactos/dll/win32/netcfgx/netcfg_iface.c b/reactos/dll/win32/netcfgx/netcfg_iface.c index d5648046555..baed12b5cc7 100644 --- a/reactos/dll/win32/netcfgx/netcfg_iface.c +++ b/reactos/dll/win32/netcfgx/netcfg_iface.c @@ -178,7 +178,6 @@ EnumClientServiceProtocol(HKEY hKey, const GUID * pGuid, NetCfgComponentItem ** NetCfgComponentItem * pLast = NULL, *pCurrent; *pHead = NULL; - do { dwCharacteristics = 0; @@ -191,29 +190,25 @@ EnumClientServiceProtocol(HKEY hKey, const GUID * pGuid, NetCfgComponentItem ** if (!pCurrent) return E_OUTOFMEMORY; - pCurrent->bChanged = FALSE; - pCurrent->pNext = NULL; - pCurrent->Status = 0; /* unused */ - pCurrent->szNodeId = 0; /* unused */ + ZeroMemory(pCurrent, sizeof(NetCfgComponentItem)); CopyMemory(&pCurrent->ClassGUID, pGuid, sizeof(GUID)); if (FAILED(CLSIDFromString(szName, &pCurrent->InstanceId))) { - CoTaskMemFree(pCurrent); - return E_FAIL; + /// ReactOS tcpip guid is not yet generated + //CoTaskMemFree(pCurrent); + //return E_FAIL; } - if (RegOpenKeyExW(hKey, szName, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) { /* retrieve Characteristics */ dwSize = sizeof(DWORD); - pCurrent->dwCharacteristics = 0; + RegQueryValueExW(hSubKey, L"Characteristics", NULL, &dwType, (LPBYTE)&pCurrent->dwCharacteristics, &dwSize); if (dwType != REG_DWORD) pCurrent->dwCharacteristics = 0; /* retrieve ComponentId */ - pCurrent->szId = NULL; dwSize = sizeof(szText); if (RegQueryValueExW(hSubKey, L"ComponentId", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) { @@ -227,7 +222,6 @@ EnumClientServiceProtocol(HKEY hKey, const GUID * pGuid, NetCfgComponentItem ** } /* retrieve Description */ - pCurrent->szDisplayName = NULL; dwSize = sizeof(szText); if (RegQueryValueExW(hSubKey, L"Description", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) { @@ -243,7 +237,6 @@ EnumClientServiceProtocol(HKEY hKey, const GUID * pGuid, NetCfgComponentItem ** if (RegOpenKeyExW(hKey, L"NDI", 0, KEY_READ, &hNDIKey) == ERROR_SUCCESS) { /* retrieve HelpText */ - pCurrent->szHelpText = NULL; dwSize = sizeof(szText); if (RegQueryValueExW(hNDIKey, L"HelpText", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) { @@ -256,8 +249,7 @@ EnumClientServiceProtocol(HKEY hKey, const GUID * pGuid, NetCfgComponentItem ** } } - /* retrieve HelpText */ - pCurrent->szBindName = NULL; + /* retrieve Service */ dwSize = sizeof(szText); if (RegQueryValueExW(hNDIKey, L"Service", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) { @@ -303,7 +295,7 @@ EnumerateNetworkComponent( if (SUCCEEDED(hr)) { swprintf(szName, L"SYSTEM\\CurrentControlSet\\Control\\Network\\%s", pszGuid); - if (RegOpenKeyExW(hKey, szName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { hr = EnumClientServiceProtocol(hKey, pGuid, pHead); RegCloseKey(hKey); diff --git a/reactos/dll/win32/netcfgx/netcfgx.c b/reactos/dll/win32/netcfgx/netcfgx.c index 30b0c23ecee..426a69a00b2 100644 --- a/reactos/dll/win32/netcfgx/netcfgx.c +++ b/reactos/dll/win32/netcfgx/netcfgx.c @@ -55,9 +55,34 @@ DllCanUnloadNow(void) STDAPI DllRegisterServer(void) { - //FIXME - // implement registering services - // + HKEY hKey, hSubKey; + LPOLESTR pStr; + WCHAR szName[MAX_PATH] = L"CLSID\\"; + + if (FAILED(StringFromCLSID(&CLSID_CNetCfg, &pStr))) + return SELFREG_E_CLASS; + + wcscpy(&szName[6], pStr); + CoTaskMemFree(pStr); + + if (RegCreateKeyExW(HKEY_CLASSES_ROOT, szName, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS) + return SELFREG_E_CLASS; + + if (RegCreateKeyExW(hKey, L"InProcServer32", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS) + { + if (!GetModuleFileNameW(netcfgx_hInstance, szName, sizeof(szName)/sizeof(WCHAR))) + { + RegCloseKey(hSubKey); + RegCloseKey(hKey); + return SELFREG_E_CLASS; + } + szName[(sizeof(szName)/sizeof(WCHAR))-1] = L'\0'; + RegSetValueW(hSubKey, NULL, REG_SZ, szName, (wcslen(szName)+1) * sizeof(WCHAR)); + RegSetValueExW(hSubKey, L"ThreadingModel", 0, REG_SZ, (LPBYTE)L"Both", 10); + RegCloseKey(hSubKey); + } + + RegCloseKey(hKey); return S_OK; } diff --git a/reactos/dll/win32/netcfgx/netcfgx.rbuild b/reactos/dll/win32/netcfgx/netcfgx.rbuild index 9df9ec67b73..ca66d46c5ba 100644 --- a/reactos/dll/win32/netcfgx/netcfgx.rbuild +++ b/reactos/dll/win32/netcfgx/netcfgx.rbuild @@ -1,5 +1,6 @@ + ntdll rpcrt4 setupapi diff --git a/reactos/dll/win32/netcfgx/precomp.h b/reactos/dll/win32/netcfgx/precomp.h index 502fe54fd63..66e06a61a5a 100644 --- a/reactos/dll/win32/netcfgx/precomp.h +++ b/reactos/dll/win32/netcfgx/precomp.h @@ -10,6 +10,7 @@ #include #include #include +#include typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject); typedef struct { diff --git a/reactos/dll/win32/netshell/lanconnectui.c b/reactos/dll/win32/netshell/lanconnectui.c index 314fbcab187..727d0d87432 100644 --- a/reactos/dll/win32/netshell/lanconnectui.c +++ b/reactos/dll/win32/netshell/lanconnectui.c @@ -135,17 +135,20 @@ EnumComponents(HWND hDlgCtrl, INetConnectionPropertyUiImpl * This, INetCfg * pNC pHelpText = NULL; hr = INetCfgComponent_GetDisplayName(pNCfgComp, &pDisplayName); hr = INetCfgComponent_GetHelpText(pNCfgComp, &pHelpText); + bChecked = TRUE; //ReactOS hack hr = INetCfgComponent_QueryInterface(pNCfgComp, &IID_INetCfgComponentBindings, (LPVOID*)&pCompBind); - - bChecked = FALSE; - if (GetINetCfgComponent(pNCfg, This, &pAdapterCfgComp)) + if (SUCCEEDED(hr)) { - hr = INetCfgComponentBindings_IsBoundTo(pCompBind, pAdapterCfgComp); - if (hr == S_OK) - bChecked = TRUE; - else - bChecked = FALSE; - INetCfgComponent_Release(pAdapterCfgComp); + if (GetINetCfgComponent(pNCfg, This, &pAdapterCfgComp)) + { + hr = INetCfgComponentBindings_IsBoundTo(pCompBind, pAdapterCfgComp); + if (hr == S_OK) + bChecked = TRUE; + else + bChecked = FALSE; + INetCfgComponent_Release(pAdapterCfgComp); + INetCfgComponentBindings_Release(pCompBind); + } } pItem = CoTaskMemAlloc(sizeof(NET_ITEM)); if (!pItem)