summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Simpkins <adam@adamsimpkins.net>2017-08-03 15:11:53 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-03-03 13:51:28 -0800
commit9e5fa7c8c26f78e121ffad0d7a745a674c4a1849 (patch)
treedb29c5ebb0b7939d8f09b9f9d56e7de3a7b2bbdf
parent3316ccaca35dc5fc6b6e3b5826e222cd648eb9c9 (diff)
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 <alan.coopersmith@oracle.com>
-rw-r--r--xrandr.c17
1 files 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;