summary refs log tree commit diff stats
path: root/src/common/inbound.c
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2017-10-25 15:26:26 -0400
committerPatrick Griffis <tingping@tingping.se>2017-10-25 15:26:26 -0400
commitc6d9e26e2b35377cba33b0b9e8e30c371bdf68ba (patch)
treeb96181e89ad4f542a3deee9891934a7e43494d31 /src/common/inbound.c
parenta3db4e577307742965f5ba75daf03146164bd211 (diff)
Fix crash when connect commands change network
Fixes #2084
Diffstat (limited to 'src/common/inbound.c')
-rw-r--r--src/common/inbound.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/common/inbound.c b/src/common/inbound.c
index 8d299ed8..fb8eb511 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -1558,6 +1558,7 @@ inbound_login_end (session *sess, char *text, const message_tags_data *tags_data
 	GSList *cmdlist;
 	commandentry *cmd;
 	server *serv = sess->server;
+	ircnet *net = serv->network;
 
 	if (!serv->end_of_motd)
 	{
@@ -1568,29 +1569,32 @@ inbound_login_end (session *sess, char *text, const message_tags_data *tags_data
 		}
 		set_default_modes (serv);
 
-		if (serv->network)
+		if (net)
 		{
 			/* there may be more than 1, separated by \n */
 
-			cmdlist = ((ircnet *)serv->network)->commandlist;
+			cmdlist = net->commandlist;
 			while (cmdlist)
 			{
 				cmd = cmdlist->data;
 				inbound_exec_eom_cmd (cmd->command, sess);
 				cmdlist = cmdlist->next;
 			}
+		}
+		/* The previously ran commands can alter the state of the server */
+		if (serv->network != net)
+			return;
 
-			/* send nickserv password */
-			if (((ircnet *)serv->network)->pass && inbound_nickserv_login (serv))
-			{
-				serv->p_ns_identify (serv, ((ircnet *)serv->network)->pass);
-			}
+		/* send nickserv password */
+		if (net && net->pass && inbound_nickserv_login (serv))
+		{
+			serv->p_ns_identify (serv, net->pass);
 		}
 
 		/* wait for join if command or nickserv set */
-		if (serv->network && prefs.hex_irc_join_delay
-			&& ((((ircnet *)serv->network)->pass && inbound_nickserv_login (serv))
-				|| ((ircnet *)serv->network)->commandlist))
+		if (net && prefs.hex_irc_join_delay
+			&& ((net->pass && inbound_nickserv_login (serv))
+				|| net->commandlist))
 		{
 			serv->joindelay_tag = fe_timeout_add_seconds (prefs.hex_irc_join_delay, check_autojoin_channels, serv);
 		}