about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-03-03 15:01:40 +0100
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-03-13 13:21:40 +0100
commit764a7fb71b6cc401ed77233bbcd4d67201f9ca85 (patch)
treead6c48e63eb765a2711e45ef8d03dbf9f313a113
parent07e584734db1b54ed3573c725b79912868a9cd7e (diff)
downloadprofani-tty-764a7fb71b6cc401ed77233bbcd4d67201f9ca85.tar.gz
prevent segfault
In case we're not connected yet and press Alt+c a segfault occurred
since `conn.xmpp_conn` is dereferenced while it's still `NULL`.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
-rw-r--r--src/tools/editor.c3
-rw-r--r--src/xmpp/connection.c12
2 files changed, 11 insertions, 4 deletions
diff --git a/src/tools/editor.c b/src/tools/editor.c
index 10c5c7d4..594e079a 100644
--- a/src/tools/editor.c
+++ b/src/tools/editor.c
@@ -51,6 +51,9 @@ get_message_from_editor(gchar* message, gchar** returned_message)
 {
     // create editor dir if not present
     char* jid = connection_get_barejid();
+    if (!jid) {
+        return TRUE;
+    }
     gchar* path = files_get_account_data_path(DIR_EDITOR, jid);
     free(jid);
     if (g_mkdir_with_parents(path, S_IRWXU) != 0) {
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index c5475258..d601de22 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -747,6 +747,8 @@ connection_get_ctx(void)
 const char*
 connection_get_fulljid(void)
 {
+    if (!conn.xmpp_conn)
+        return NULL;
     const char* jid = xmpp_conn_get_bound_jid(conn.xmpp_conn);
     if (jid) {
         return jid;
@@ -759,10 +761,11 @@ char*
 connection_get_barejid(void)
 {
     const char* jid = connection_get_fulljid();
-    char* result;
+    if (!jid)
+        return NULL;
 
     Jid* jidp = jid_create(jid);
-    result = strdup(jidp->barejid);
+    char* result = strdup(jidp->barejid);
     jid_destroy(jidp);
 
     return result;
@@ -772,8 +775,9 @@ char*
 connection_get_user(void)
 {
     const char* jid = connection_get_fulljid();
-    char* result;
-    result = strdup(jid);
+    if (!jid)
+        return NULL;
+    char* result = strdup(jid);
 
     char* split = strchr(result, '@');
     *split = '\0';