Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/user32/sysparams.c | 16 +++++++++++++++- dlls/user32/tests/monitor.c | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 14d3778a535..d4462e589e8 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -3307,7 +3307,8 @@ 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]; + WCHAR primary_adapter[CCHDEVICENAME], *end; + long int display_idx; BOOL def_mode = TRUE; DEVMODEW dm; LONG ret; @@ -3331,6 +3332,19 @@ 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) + { + ERR("Invalid device name %s.\n", wine_dbgstr_w(devname)); + return DISP_CHANGE_BADPARAM; + } + if (devmode) { trace_devmode(devmode); diff --git a/dlls/user32/tests/monitor.c b/dlls/user32/tests/monitor.c index fe763e46b48..badbfdaacf3 100644 --- a/dlls/user32/tests/monitor.c +++ b/dlls/user32/tests/monitor.c @@ -369,13 +369,13 @@ static void test_ChangeDisplaySettingsEx(void) ok(res, "EnumDisplaySettingsA failed, error %#x\n", GetLastError());
res = ChangeDisplaySettingsExA("invalid", &dm, NULL, CDS_TEST, NULL); - todo_wine ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res); + ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res);
res = ChangeDisplaySettingsExA("\\.\DISPLAY0", &dm, NULL, CDS_TEST, NULL); - todo_wine ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res); + ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res);
res = ChangeDisplaySettingsExA("\\.\DISPLAY1\Monitor0", &dm, NULL, CDS_TEST, NULL); - todo_wine ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res); + ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res);
/* Test dmDriverExtra */ memset(&dm, 0, sizeof(dm));