From 6f22afd9e96ffa8f53800ac7055286dd76999a73 Mon Sep 17 00:00:00 2001 From: Sun Peng Date: Tue, 9 Aug 2022 16:23:44 +0800 Subject: [PATCH] dm: vdisplay: Add physical monitor id check. vdisplay use physical monitor id(pscreen index) to locate the monitor. The max index value always is the physical monitor number - 1. For example, there are 4 physical monitors connected. The monitor id should be 0, 1, 2 and 3. We need check monitor id that user inputs and make sure it is in a correct range. Tracked-On: #7988 Signed-off-by: Sun Peng Reviewed-by: Zhao Yakui --- devicemodel/hw/vdisplay_sdl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/devicemodel/hw/vdisplay_sdl.c b/devicemodel/hw/vdisplay_sdl.c index 09655eb7a..b8e526d2a 100644 --- a/devicemodel/hw/vdisplay_sdl.c +++ b/devicemodel/hw/vdisplay_sdl.c @@ -1151,6 +1151,7 @@ int gfx_ui_init() { SDL_SysWMinfo info; + int num_pscreen; setenv("SDL_VIDEO_X11_FORCE_EGL", "1", 1); setenv("SDL_OPENGL_ES_DRIVER", "1", 1); @@ -1162,6 +1163,14 @@ gfx_ui_init() return -1; } + num_pscreen = SDL_GetNumVideoDisplays(); + if (vdpy.pscreen_id >= num_pscreen) { + pr_err("Monitor id %d is out of avalble range [0~%d].\n", + vdpy.pscreen_id, num_pscreen); + SDL_Quit(); + return -1; + } + SDL_GetDisplayBounds(vdpy.pscreen_id, &vdpy.pscreen_rect); if (vdpy.pscreen_rect.w < VDPY_MIN_WIDTH ||