From 9e5fa7c8c26f78e121ffad0d7a745a674c4a1849 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Thu, 3 Aug 2017 15:11:53 -0700 Subject: xrandr: fix crash if some modes cannot be found 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. Signed-off-by: Alan Coopersmith --- xrandr.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/xrandr.c b/xrandr.c index ce3cd91..0eff3c1 100644 --- a/xrandr.c +++ b/xrandr.c @@ -3927,6 +3927,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); @@ -3941,16 +3947,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; -- cgit v1.2.3