[PATCH v4 2/2] dm: vdisplay: Add physical monitor id check.


Sun, Peng
 

From: Sun Peng <peng.p.sun@...>

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.

Signed-off-by: Sun Peng <peng.p.sun@...>
Reviewed-by: Zhao Yakui <yakui.zhao@...>
---
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 cea26d3ee..403047a3c 100644
--- a/devicemodel/hw/vdisplay_sdl.c
+++ b/devicemodel/hw/vdisplay_sdl.c
@@ -1141,6 +1141,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);
@@ -1152,6 +1153,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 ||
--
2.25.1