Commit 46182aa5 authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

user32: Check invalid device names in EnumDisplaySettingsExW().

parent 8928a417
......@@ -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 "
......
......@@ -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));
......
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