[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] hc: don't segfault if DISPLAY can't be opened



Yes, I know, I'm bombarding this ML with patches. I'm done soon with
the smaller things I think.

While developing I accidentally did run herbstclient over an SSH
connection without DISPLAY set and it segfaulted, I thought it might
be better to output some error message and exit gracefully.

If there is any better way of contributing (e.g. you pulling from my
git repo or whatever) that's fine for me as well, just let me know.

Florian

-- 
() ascii ribbon campaign - stop html mail    www.asciiribbon.org
/\ www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
Many people are unenthusiastic about your work. 
>From 872372a84c316bad759798c9c4766032d4fc8bf2 Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org>
Date: Mon, 5 Nov 2012 13:24:44 +0100
Subject: [PATCH] Don't segfault when DISPLAY can't be opened in hc

herbstclient should output an error message and exit instead of segfaulting
when DISPLAY is unset or can't be opened.
---
 ipc-client/ipc-client.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ipc-client/ipc-client.c b/ipc-client/ipc-client.c
index 813cede..3c25613 100644
--- a/ipc-client/ipc-client.c
+++ b/ipc-client/ipc-client.c
@@ -33,6 +33,9 @@ struct HCConnection {
 
 HCConnection* hc_connect() {
     Display* display = XOpenDisplay(NULL);
+    if (display == NULL) {
+        return NULL;
+    } 
     HCConnection* con = hc_connect_to_display(display);
     if (con) {
         con->own_display = true;
@@ -153,6 +156,9 @@ bool hc_send_command(HCConnection* con, int argc, char* argv[],
 bool hc_send_command_once(int argc, char* argv[],
                           GString** ret_out, int* ret_status) {
     HCConnection* con = hc_connect();
+    if (con == NULL) {
+        return false;
+    }
     bool status = hc_send_command(con, argc, argv, ret_out, ret_status);
     hc_disconnect(con);
     return status;
-- 
1.8.0