Fixed possible NULL-deref and removed unnecessary XOpenDisplay()
authorAaron Marcher <me@drkhsh.at>
Fri, 11 Aug 2017 12:33:02 +0000 (14:33 +0200)
committerAaron Marcher <me@drkhsh.at>
Fri, 11 Aug 2017 12:33:02 +0000 (14:33 +0200)
- Added a check for the return value of XOpenDisplay() in main().
  This fixes a possible NULL-deref.
- Removed unnsecessary XOpenDisplay and XCloseDisplay from
  keyboard_indicators(). The ones in main() are sufficent.

slstatus.c

index 596d6a610e262ef2fe462dec84053f202eaac66e..47bd4c9926000177f36dee315274af958d6d6e8c 100644 (file)
@@ -380,10 +380,9 @@ kernel_release(void)
 static const char *
 keyboard_indicators(void)
 {
-       Display *dpy = XOpenDisplay(NULL);
        XKeyboardState state;
+
        XGetKeyboardControl(dpy, &state);
-       XCloseDisplay(dpy);
 
        switch (state.led_mask) {
                case 1:
@@ -879,6 +878,10 @@ main(int argc, char *argv[])
 
        if (!sflag) {
                dpy = XOpenDisplay(NULL);
+               if (!dpy) {
+                       fprintf(stderr, "slstatus: cannot open display");
+                       exit(1);
+               }
        }
 
        setlocale(LC_ALL, "");