Fix segmentation fault on IRC server reply release-2.x.y

Mon, 30 May 2022 20:52:30 -0500

author
Belgin Știrbu <belginstirbu@hotmail.com>
date
Mon, 30 May 2022 20:52:30 -0500
branch
release-2.x.y
changeset 41415
31b24663dd5f
parent 41412
1912d331d78c
child 41417
536fd9c928aa

Fix segmentation fault on IRC server reply

When Pidgin received `:nick!user@host JOIN #channel` from an IRC
server, it worked fine, but when it received
`:nick JOIN #channel`, it crashed with a segmentation fault.

Testing Done:
Tested with a custom IRC server that only sends the nickname. Also tested on Libera Chat.

Bugs closed: PIDGIN-17375

Reviewed at https://reviews.imfreedom.org/r/1484/

libpurple/protocols/irc/msgs.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/irc/msgs.c	Fri May 27 03:32:41 2022 -0500
+++ b/libpurple/protocols/irc/msgs.c	Mon May 30 20:52:30 2022 -0500
@@ -71,7 +71,14 @@
 
 static char *irc_mask_userhost(const char *mask)
 {
-	return g_strdup(strchr(mask, '!') + 1);
+	char *sep = strchr(mask, '!');
+	char *host = "";
+
+	if(sep) {
+		host = sep + 1;
+	}
+
+	return g_strdup(host);
 }
 
 static void irc_chat_remove_buddy(PurpleConversation *convo, char *data[2])

mercurial