Skip to content

Commit 967f5b9

Browse files
committed
[WINLOGON] Protect function calls to '3rd-party' DLLs by SEH. (reactos#4743)
This includes: - Notification dll calling in CallNotificationDll(). - winmm.dll API calling (e.g. PlaySound) in PlaySoundRoutine(). Also: - Fix dwKeyName usage in RegEnumKeyExW() specifying a number of *characters*.
1 parent ab3e000 commit 967f5b9

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

base/system/winlogon/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ list(APPEND SOURCE
2121

2222
add_rc_deps(winlogon.rc ${CMAKE_CURRENT_SOURCE_DIR}/res/winlogon.ico)
2323
add_executable(winlogon ${SOURCE} winlogon.rc)
24-
target_link_libraries(winlogon wine)
24+
target_link_libraries(winlogon wine ${PSEH_LIB})
2525
set_module_type(winlogon win32gui)
2626
add_importlibs(winlogon user32 advapi32 userenv secur32 rpcrt4 mpr msvcrt kernel32 ntdll)
2727
add_pch(winlogon winlogon.h SOURCE)

base/system/winlogon/notify.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ InitNotifications(VOID)
278278
dwIndex = 0;
279279
for(;;)
280280
{
281-
dwKeyName = 80 * sizeof(WCHAR);
281+
dwKeyName = ARRAYSIZE(szKeyName);
282282
lError = RegEnumKeyExW(hNotifyKey,
283283
dwIndex,
284284
szKeyName,
@@ -312,11 +312,8 @@ CallNotificationDll(
312312
NOTIFICATION_TYPE Type,
313313
PWLX_NOTIFICATION_INFO pInfo)
314314
{
315-
HKEY hDllKey = NULL;
316-
HMODULE hModule = NULL;
315+
HMODULE hModule;
317316
CHAR szFuncBuffer[128];
318-
DWORD dwSize;
319-
DWORD dwType;
320317
DWORD dwError = ERROR_SUCCESS;
321318
PWLX_NOTIFY_HANDLER pNotifyHandler;
322319

@@ -338,6 +335,10 @@ CallNotificationDll(
338335
}
339336
else
340337
{
338+
HKEY hDllKey;
339+
DWORD dwSize;
340+
DWORD dwType;
341+
341342
dwError = RegOpenKeyExW(hNotifyKey,
342343
NotificationDll->pszKeyName,
343344
0,
@@ -356,23 +357,32 @@ CallNotificationDll(
356357
&dwType,
357358
(PBYTE)szFuncBuffer,
358359
&dwSize);
360+
361+
RegCloseKey(hDllKey);
359362
}
360363

361-
if (dwError == ERROR_SUCCESS)
362-
{
363-
hModule = LoadLibraryW(NotificationDll->pszDllName);
364-
if (hModule != NULL)
365-
{
366-
pNotifyHandler = (PWLX_NOTIFY_HANDLER)GetProcAddress(hModule, szFuncBuffer);
367-
if (pNotifyHandler != NULL)
368-
pNotifyHandler(pInfo);
364+
if (dwError != ERROR_SUCCESS)
365+
return;
369366

370-
FreeLibrary(hModule);
371-
}
367+
hModule = LoadLibraryW(NotificationDll->pszDllName);
368+
if (!hModule)
369+
return;
370+
371+
pNotifyHandler = (PWLX_NOTIFY_HANDLER)GetProcAddress(hModule, szFuncBuffer);
372+
373+
_SEH2_TRY
374+
{
375+
if (pNotifyHandler)
376+
pNotifyHandler(pInfo);
377+
}
378+
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
379+
{
380+
ERR("WL: Exception while running notification %S!%s, Status 0x%08lx\n",
381+
NotificationDll->pszDllName, szFuncBuffer, _SEH2_GetExceptionCode());
372382
}
383+
_SEH2_END;
373384

374-
if (hDllKey != NULL)
375-
RegCloseKey(hDllKey);
385+
FreeLibrary(hModule);
376386
}
377387

378388

base/system/winlogon/sas.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,30 +251,36 @@ PlaySoundRoutine(
251251
BOOL Ret = FALSE;
252252

253253
hLibrary = LoadLibraryW(L"winmm.dll");
254-
if (hLibrary)
254+
if (!hLibrary)
255+
return FALSE;
256+
257+
waveOutGetNumDevs = (WAVEOUTGETNUMDEVS)GetProcAddress(hLibrary, "waveOutGetNumDevs");
258+
Play = (PLAYSOUNDW)GetProcAddress(hLibrary, "PlaySoundW");
259+
260+
_SEH2_TRY
255261
{
256-
waveOutGetNumDevs = (WAVEOUTGETNUMDEVS)GetProcAddress(hLibrary, "waveOutGetNumDevs");
257262
if (waveOutGetNumDevs)
258263
{
259264
NumDevs = waveOutGetNumDevs();
260265
if (!NumDevs)
261266
{
262267
if (!bLogon)
263-
{
264268
Beep(440, 125);
265-
}
266-
FreeLibrary(hLibrary);
267-
return FALSE;
269+
_SEH2_LEAVE;
268270
}
269271
}
270272

271-
Play = (PLAYSOUNDW)GetProcAddress(hLibrary, "PlaySoundW");
272273
if (Play)
273-
{
274274
Ret = Play(FileName, NULL, Flags);
275-
}
276-
FreeLibrary(hLibrary);
277275
}
276+
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
277+
{
278+
ERR("WL: Exception while playing sound '%S', Status 0x%08lx\n",
279+
FileName ? FileName : L"(n/a)", _SEH2_GetExceptionCode());
280+
}
281+
_SEH2_END;
282+
283+
FreeLibrary(hLibrary);
278284

279285
return Ret;
280286
}

base/system/winlogon/winlogon.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
#ifndef __WINLOGON_MAIN_H__
2727
#define __WINLOGON_MAIN_H__
2828

29-
#include <stdarg.h>
30-
3129
#define USE_GETLASTINPUTINFO
3230

31+
32+
#include <stdarg.h>
33+
34+
/* PSDK/NDK Headers */
3335
#define WIN32_NO_STATUS
3436
#include <windef.h>
3537
#include <winbase.h>
@@ -41,6 +43,9 @@
4143
#include <ndk/exfuncs.h>
4244
#include <strsafe.h>
4345

46+
/* PSEH for SEH Support */
47+
#include <pseh/pseh2.h>
48+
4449
#include <reactos/undocuser.h>
4550
#include <reactos/undocmpr.h>
4651

0 commit comments

Comments
 (0)