[PATCH app/xrandr] xrandr: fix crash if some modes cannot be found

Adam Simpkins adam at adamsimpkins.net
Thu Aug 3 22:11:53 UTC 2017


When printing modes in "xrandr -q", check to see if we failed to look up
mode information from a mode XID.  Previously the command would
dereference null and crash if the mode information could not be found.

When using an external HDMI monitor on a laptop with a Skylake Intel
graphics chipset "xrandr -q" occasionally is unable to look up mode
information for some of the modes.  It seems likely there is some other
sort of library or driver issue causing these lookup failures, but this
change to xrandr at least prevents it from segfaulting.
---
 xrandr.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index 2d4cb72..186cae2 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -3908,6 +3908,12 @@ main (int argc, char **argv)
 		for (j = 0; j < output_info->nmode; j++)
 		{
 		    XRRModeInfo	*mode = find_mode_by_xid (output_info->modes[j]);
+		    if (!mode)
+		    {
+			printf ("  [Unknown mode ID 0x%x]\n",
+				(int)output_info->modes[j]);
+			continue;
+		    }
 
 		    print_verbose_mode (mode, mode == output->mode_info,
 					j < output_info->npreferred);
@@ -3922,16 +3928,23 @@ main (int argc, char **argv)
 		{
 		    XRRModeInfo *jmode, *kmode;
 		    int k;
-		    
+
 		    if (mode_shown[j]) continue;
-    
+
 		    jmode = find_mode_by_xid (output_info->modes[j]);
+		    if (!jmode)
+		    {
+			printf ("   [Unknown mode ID 0x%x]\n",
+				(int)output_info->modes[j]);
+			continue;
+		    }
 		    printf (" ");
 		    printf ("  %-12s", jmode->name);
 		    for (k = j; k < output_info->nmode; k++)
 		    {
 			if (mode_shown[k]) continue;
 			kmode = find_mode_by_xid (output_info->modes[k]);
+			if (!kmode) continue;
 			if (strcmp (jmode->name, kmode->name) != 0) continue;
 			mode_shown[k] = True;
 			kmode->modeFlags |= ModeShown;
-- 
2.11.0



More information about the xorg-devel mailing list