Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/user32/sysparams.c | 33 +++++++++++++++++++++++---------- dlls/user32/tests/sysparams.c | 8 ++++---- 2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index d4462e589e8..79f938a3c20 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -590,6 +590,21 @@ static BOOL get_primary_adapter(WCHAR *name) return FALSE; }
+static BOOL is_valid_adapter_name(const WCHAR *name) +{ + long int adapter_idx; + WCHAR *end; + + if (strncmpiW(name, ADAPTER_PREFIX, ARRAY_SIZE(ADAPTER_PREFIX))) + return FALSE; + + adapter_idx = strtolW(name + ARRAY_SIZE(ADAPTER_PREFIX), &end, 10); + if (*end || adapter_idx < 1) + return FALSE; + + return TRUE; +} + /* get text metrics and/or "average" char width of the specified logfont * for the specified dc */ static void get_text_metr_size( HDC hdc, LOGFONTW *plf, TEXTMETRICW * ptm, UINT *psz) @@ -3307,8 +3322,7 @@ static BOOL is_detached_mode(const DEVMODEW *mode) LONG WINAPI ChangeDisplaySettingsExW( LPCWSTR devname, LPDEVMODEW devmode, HWND hwnd, DWORD flags, LPVOID lparam ) { - WCHAR primary_adapter[CCHDEVICENAME], *end; - long int display_idx; + WCHAR primary_adapter[CCHDEVICENAME]; BOOL def_mode = TRUE; DEVMODEW dm; LONG ret; @@ -3332,14 +3346,7 @@ LONG WINAPI ChangeDisplaySettingsExW( LPCWSTR devname, LPDEVMODEW devmode, HWND devname = primary_adapter; }
- if (strncmpiW(devname, ADAPTER_PREFIX, ARRAY_SIZE(ADAPTER_PREFIX))) - { - ERR("Invalid device name %s.\n", wine_dbgstr_w(devname)); - return DISP_CHANGE_BADPARAM; - } - - display_idx = strtolW(devname + ARRAY_SIZE(ADAPTER_PREFIX), &end, 10); - if (*end || display_idx < 1) + if (!is_valid_adapter_name(devname)) { ERR("Invalid device name %s.\n", wine_dbgstr_w(devname)); return DISP_CHANGE_BADPARAM; @@ -3466,6 +3473,12 @@ BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum, lpszDeviceName = primary_adapter; }
+ if (!is_valid_adapter_name(lpszDeviceName)) + { + ERR("Invalid device name %s.\n", wine_dbgstr_w(lpszDeviceName)); + return FALSE; + } + ret = USER_Driver->pEnumDisplaySettingsEx(lpszDeviceName, iModeNum, lpDevMode, dwFlags); if (ret) TRACE("device:%s mode index:%#x position:(%d,%d) resolution:%ux%u frequency:%uHz " diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index 6750325a291..f71b73930f2 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -3154,18 +3154,18 @@ static void test_EnumDisplaySettings(void) dm.dmSize = sizeof(dm); SetLastError(0xdeadbeef); ret = EnumDisplaySettingsA("invalid", ENUM_CURRENT_SETTINGS, &dm); - todo_wine ok(!ret, "EnumDisplaySettingsA succeeded\n"); + ok(!ret, "EnumDisplaySettingsA succeeded\n"); ok(GetLastError() == 0xdeadbeef, "Expect error 0xdeadbeef, got %#x\n", GetLastError()); - todo_wine ok(dm.dmFields == 0, "Expect dmFields unchanged, got %#x\n", dm.dmFields); + ok(dm.dmFields == 0, "Expect dmFields unchanged, got %#x\n", dm.dmFields);
/* Monitor device names are invalid */ memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); SetLastError(0xdeadbeef); ret = EnumDisplaySettingsA("\\.\DISPLAY1\Monitor0", ENUM_CURRENT_SETTINGS, &dm); - todo_wine ok(!ret, "EnumDisplaySettingsA succeeded\n"); + ok(!ret, "EnumDisplaySettingsA succeeded\n"); ok(GetLastError() == 0xdeadbeef, "Expect error 0xdeadbeef, got %#x\n", GetLastError()); - todo_wine ok(dm.dmFields == 0, "Expect dmFields unchanged, got %#x\n", dm.dmFields); + ok(dm.dmFields == 0, "Expect dmFields unchanged, got %#x\n", dm.dmFields);
/* Test that passing NULL to device name parameter means to use the primary adapter */ memset(&dm, 0, sizeof(dm));