From 5a5c926ec0dffa4b28895929c092089c2a9b9d9f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 12 Jun 2006 08:58:20 +0200 Subject: Fixed a (very rare, AFAIK) NULL-pointer dereference. --- protocols/msn/msn.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 3c7064f8..bac9c427 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -63,33 +63,38 @@ static void msn_close( struct gaim_connection *gc ) struct msn_data *md = gc->proto_data; GSList *l; - if( md->fd >= 0 ) - closesocket( md->fd ); - - if( md->handler ) - { - if( md->handler->rxq ) g_free( md->handler->rxq ); - if( md->handler->cmd_text ) g_free( md->handler->cmd_text ); - g_free( md->handler ); - } - - while( md->switchboards ) - msn_sb_destroy( md->switchboards->data ); - - if( md->msgq ) + if( md ) { - struct msn_message *m; + if( md->fd >= 0 ) + closesocket( md->fd ); - for( l = md->msgq; l; l = l->next ) + if( md->handler ) { - m = l->data; + if( md->handler->rxq ) g_free( md->handler->rxq ); + if( md->handler->cmd_text ) g_free( md->handler->cmd_text ); + g_free( md->handler ); + } - serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); - g_free( m->who ); - g_free( m->text ); - g_free( m ); + while( md->switchboards ) + msn_sb_destroy( md->switchboards->data ); + + if( md->msgq ) + { + struct msn_message *m; + + for( l = md->msgq; l; l = l->next ) + { + m = l->data; + + serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); + g_free( m->who ); + g_free( m->text ); + g_free( m ); + } + g_slist_free( md->msgq ); } - g_slist_free( md->msgq ); + + g_free( md ); } for( l = gc->permit; l; l = l->next ) @@ -100,8 +105,6 @@ static void msn_close( struct gaim_connection *gc ) g_free( l->data ); g_slist_free( gc->deny ); - g_free( md ); - msn_connections = g_slist_remove( msn_connections, gc ); } -- cgit v1.2.3 From 79e826a028f4b4c62c0c16e20af1fb13a9636324 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 15 Jun 2006 14:22:17 +0200 Subject: Converted irc->status to binary flags. (This also fixes auto-save-on-quit that broke because of USTATUS_SHUTDOWN. :-( ) --- bitlbee.c | 2 +- ipc.c | 10 +++++----- irc.c | 10 +++++----- irc.h | 8 ++++---- irc_commands.c | 6 +++--- root_commands.c | 6 +++--- storage_text.c | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bitlbee.c b/bitlbee.c index 3aca30c5..8cceca6f 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -235,7 +235,7 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi irc->sendbuffer = NULL; irc->w_watch_source_id = 0; - if( irc->status == USTATUS_SHUTDOWN ) + if( irc->status & USTATUS_SHUTDOWN ) irc_free( irc ); return( FALSE ); diff --git a/ipc.c b/ipc.c index 18d3284e..5a23d1f9 100644 --- a/ipc.c +++ b/ipc.c @@ -114,7 +114,7 @@ static void ipc_child_cmd_die( irc_t *irc, char **cmd ) static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( strchr( irc->umode, 'w' ) ) @@ -123,7 +123,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( strchr( irc->umode, 's' ) ) @@ -132,7 +132,7 @@ static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( strchr( irc->umode, 'o' ) ) @@ -153,7 +153,7 @@ static void ipc_child_cmd_rehash( irc_t *irc, char **cmd ) static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( nick_cmp( cmd[1], irc->nick ) != 0 ) @@ -165,7 +165,7 @@ static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) static void ipc_child_cmd_hello( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) ipc_to_master_str( "HELLO\r\n" ); else ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname ); diff --git a/irc.c b/irc.c index 3d3baca6..cd30d1c2 100644 --- a/irc.c +++ b/irc.c @@ -178,7 +178,7 @@ void irc_abort( irc_t *irc, int immed, char *format, ... ) irc->nick ? irc->nick : "(NONE)", irc->host, "No reason given" ); } - irc->status = USTATUS_SHUTDOWN; + irc->status |= USTATUS_SHUTDOWN; if( irc->sendbuffer && !immed ) { /* We won't read from this socket anymore. Instead, we'll connect a timer @@ -212,7 +212,7 @@ void irc_free(irc_t * irc) log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd ); - if( irc->status >= USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) + if( irc->status & USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) if( storage_save( irc, TRUE ) != STORAGE_OK ) irc_usermsg( irc, "Error while saving settings!" ); @@ -700,7 +700,7 @@ int irc_check_login( irc_t *irc ) { if( irc->user && irc->nick ) { - if( global.conf->authmode == AUTHMODE_CLOSED && irc->status < USTATUS_AUTHORIZED ) + if( global.conf->authmode == AUTHMODE_CLOSED && ! irc->status & USTATUS_AUTHORIZED ) { irc_reply( irc, 464, ":This server is password-protected." ); return 0; @@ -757,7 +757,7 @@ void irc_login( irc_t *irc ) if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON ) ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname ); - irc->status = USTATUS_LOGGED_IN; + irc->status |= USTATUS_LOGGED_IN; } void irc_motd( irc_t *irc ) @@ -1180,7 +1180,7 @@ static gboolean irc_userping( gpointer _irc ) irc_t *irc = _irc; int rv = 0; - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) { if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) ) rv = gettime() - irc->last_pong; diff --git a/irc.h b/irc.h index 79faea0b..1dc12849 100644 --- a/irc.h +++ b/irc.h @@ -41,10 +41,10 @@ typedef enum { USTATUS_OFFLINE = 0, - USTATUS_AUTHORIZED, - USTATUS_LOGGED_IN, - USTATUS_IDENTIFIED, - USTATUS_SHUTDOWN = -1 + USTATUS_AUTHORIZED = 1, + USTATUS_LOGGED_IN = 2, + USTATUS_IDENTIFIED = 4, + USTATUS_SHUTDOWN = 8 } irc_status_t; typedef struct channel diff --git a/irc_commands.c b/irc_commands.c index dc59f7ee..519070db 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -31,7 +31,7 @@ static void irc_cmd_pass( irc_t *irc, char **cmd ) { if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 ) { - irc->status = USTATUS_AUTHORIZED; + irc->status |= USTATUS_AUTHORIZED; irc_check_login( irc ); } else @@ -609,11 +609,11 @@ void irc_exec( irc_t *irc, char *cmd[] ) /* There should be no typo in the next line: */ for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --; - if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN ) + if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN ) { irc_reply( irc, 462, ":Only allowed before logging in" ); } - else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN ) + else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && ! irc->status & USTATUS_LOGGED_IN ) { irc_reply( irc, 451, ":Register first" ); } diff --git a/root_commands.c b/root_commands.c index 0e12e9ab..d8611347 100644 --- a/root_commands.c +++ b/root_commands.c @@ -162,7 +162,7 @@ static void cmd_register( irc_t *irc, char **cmd ) break; case STORAGE_OK: - irc->status = USTATUS_IDENTIFIED; + irc->status |= USTATUS_IDENTIFIED; irc_umode_set( irc, "+R", 1 ); break; @@ -186,7 +186,7 @@ static void cmd_drop( irc_t *irc, char **cmd ) break; case STORAGE_OK: irc_setpass( irc, NULL ); - irc->status = USTATUS_LOGGED_IN; + irc->status &= ~USTATUS_IDENTIFIED; irc_umode_set( irc, "-R", 1 ); irc_usermsg( irc, "Account `%s' removed", irc->nick ); break; @@ -200,7 +200,7 @@ static void cmd_account( irc_t *irc, char **cmd ) { account_t *a; - if( global.conf->authmode == AUTHMODE_REGISTERED && irc->status < USTATUS_IDENTIFIED ) + if( global.conf->authmode == AUTHMODE_REGISTERED && ! irc->status & USTATUS_IDENTIFIED ) { irc_usermsg( irc, "This server only accepts registered users" ); return; diff --git a/storage_text.c b/storage_text.c index f807cb3e..506c9f03 100644 --- a/storage_text.c +++ b/storage_text.c @@ -70,7 +70,7 @@ static storage_status_t text_load ( const char *my_nick, const char* password, i FILE *fp; user_t *ru = user_find( irc, ROOT_NICK ); - if( irc->status >= USTATUS_IDENTIFIED ) + if( irc->status & USTATUS_IDENTIFIED ) return( 1 ); g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".accounts" ); @@ -87,7 +87,7 @@ static storage_status_t text_load ( const char *my_nick, const char* password, i /* Do this now. If the user runs with AuthMode = Registered, the account command will not work otherwise. */ - irc->status = USTATUS_IDENTIFIED; + irc->status |= USTATUS_IDENTIFIED; while( fscanf( fp, "%511[^\n]s", s ) > 0 ) { -- cgit v1.2.3 From 3af70b06b2f0fb0fb41a041f6d86e3711b9eea3f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 15 Jun 2006 14:37:05 +0200 Subject: !x&y == (!x)&y, not !(x&y). --- ipc.c | 10 +++++----- irc.c | 4 ++-- irc_commands.c | 2 +- root_commands.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ipc.c b/ipc.c index 5a23d1f9..d7ef1020 100644 --- a/ipc.c +++ b/ipc.c @@ -114,7 +114,7 @@ static void ipc_child_cmd_die( irc_t *irc, char **cmd ) static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( strchr( irc->umode, 'w' ) ) @@ -123,7 +123,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( strchr( irc->umode, 's' ) ) @@ -132,7 +132,7 @@ static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( strchr( irc->umode, 'o' ) ) @@ -153,7 +153,7 @@ static void ipc_child_cmd_rehash( irc_t *irc, char **cmd ) static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( nick_cmp( cmd[1], irc->nick ) != 0 ) @@ -165,7 +165,7 @@ static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) static void ipc_child_cmd_hello( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) ipc_to_master_str( "HELLO\r\n" ); else ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname ); diff --git a/irc.c b/irc.c index cd30d1c2..62af4b08 100644 --- a/irc.c +++ b/irc.c @@ -700,7 +700,7 @@ int irc_check_login( irc_t *irc ) { if( irc->user && irc->nick ) { - if( global.conf->authmode == AUTHMODE_CLOSED && ! irc->status & USTATUS_AUTHORIZED ) + if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) ) { irc_reply( irc, 464, ":This server is password-protected." ); return 0; @@ -1180,7 +1180,7 @@ static gboolean irc_userping( gpointer _irc ) irc_t *irc = _irc; int rv = 0; - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) { if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) ) rv = gettime() - irc->last_pong; diff --git a/irc_commands.c b/irc_commands.c index 519070db..f410bb52 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -613,7 +613,7 @@ void irc_exec( irc_t *irc, char *cmd[] ) { irc_reply( irc, 462, ":Only allowed before logging in" ); } - else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && ! irc->status & USTATUS_LOGGED_IN ) + else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) ) { irc_reply( irc, 451, ":Register first" ); } diff --git a/root_commands.c b/root_commands.c index d8611347..3d3584b3 100644 --- a/root_commands.c +++ b/root_commands.c @@ -200,7 +200,7 @@ static void cmd_account( irc_t *irc, char **cmd ) { account_t *a; - if( global.conf->authmode == AUTHMODE_REGISTERED && ! irc->status & USTATUS_IDENTIFIED ) + if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) { irc_usermsg( irc, "This server only accepts registered users" ); return; -- cgit v1.2.3