Commit a599d645 authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

user32: Check invalid device names in ChangeDisplaySettingsExW().

parent dcf8bd76
......@@ -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);
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment