diff options
author | James Booth <boothj5@gmail.com> | 2012-10-22 10:05:38 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-10-22 10:05:38 +0100 |
commit | a314e03db2a57c18f653f18c63b3dc138b0b93e9 (patch) | |
tree | 664cf3339f28062b72cbf25f9a0bbc4f9451f3ec | |
parent | 3f8813bb1b24e273d9cc3172e35b1932c06b0af0 (diff) | |
download | profani-tty-a314e03db2a57c18f653f18c63b3dc138b0b93e9.tar.gz |
Fixed possible segfault when no type attribute on incoming messages
-rw-r--r-- | src/jabber.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/jabber.c b/src/jabber.c index 8cd13310..ea7e38c4 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -255,30 +255,32 @@ static int _message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - char *type; - char *from; + char *type = NULL; + char *from = NULL; type = xmpp_stanza_get_attribute(stanza, "type"); from = xmpp_stanza_get_attribute(stanza, "from"); - if (strcmp(type, "error") == 0) { - char *err_msg = NULL; - xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error"); - if (error == NULL) { - log_debug("error message without <error/> received"); - return 1; - } else { - xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error); - if (err_cond == NULL) { - log_debug("error message without <defined-condition/> received"); + if (type != NULL) { + if (strcmp(type, "error") == 0) { + char *err_msg = NULL; + xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error"); + if (error == NULL) { + log_debug("error message without <error/> received"); return 1; } else { - err_msg = xmpp_stanza_get_name(err_cond); + xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error); + if (err_cond == NULL) { + log_debug("error message without <defined-condition/> received"); + return 1; + } else { + err_msg = xmpp_stanza_get_name(err_cond); + } + // TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2] } - // TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2] + prof_handle_error_message(from, err_msg); + return 1; } - prof_handle_error_message(from, err_msg); - return 1; } xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body"); |