Changeset c1a3c27


Ignore:
Timestamp:
2010-03-17T23:41:07Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
42fc5b6
Parents:
60e4df3
Message:

Avoid some NULL pointer dereferences on malformed XMPP packets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r60e4df3 rc1a3c27  
    658658        struct xt_node *c;
    659659        struct jabber_buddy *bud;
    660         char *feature;
     660        char *feature, *xmlns, *from;
    661661
    662662        if( !( c = xt_find_node( node->children, "query" ) ) ||
    663             !( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) )
     663            !( from = xt_find_attr( c, "from" ) ) ||
     664            !( xmlns = xt_find_attr( c, "xmlns" ) ) ||
     665            !( strcmp( xmlns, XMLNS_DISCO_INFO ) == 0 ) )
    664666        {
    665667                imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );
    666668                return XT_HANDLED;
    667669        }
    668         if( ( bud = jabber_buddy_by_jid( ic, xt_find_attr( node, "from") , 0 ) ) == NULL )
     670        if( ( bud = jabber_buddy_by_jid( ic, from, 0 ) ) == NULL )
    669671        {
    670672                /* Who cares about the unknown... */
    671                 imcb_log( ic, "Couldn't find buddy: %s", xt_find_attr( node, "from"));
     673                imcb_log( ic, "Couldn't find buddy: %s", from );
    672674                return 0;
    673675        }
     
    677679        {
    678680                feature = xt_find_attr( c, "var" );
    679                 bud->features = g_slist_append( bud->features, g_strdup( feature ) );
     681                if( feature )
     682                        bud->features = g_slist_append( bud->features, g_strdup( feature ) );
    680683                c = c->next;
    681684        }
     
    713716        struct xt_node *c;
    714717        struct jabber_data *jd = ic->proto_data;
     718        char *xmlns, *from;
    715719
    716720        if( !( c = xt_find_node( node->children, "query" ) ) ||
    717             !xt_find_attr( node, "from" ) )
     721            !( from = xt_find_attr( node, "from" ) ) ||
     722            !( xmlns = xt_find_attr( c, "xmlns" ) ) )
    718723        {
    719724                imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );
     
    723728        jd->have_streamhosts++;
    724729
    725         if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_ITEMS ) == 0 )
    726         {
    727                 char *item, *itemjid;
     730        if( strcmp( xmlns, XMLNS_DISCO_ITEMS ) == 0 )
     731        {
     732                char *itemjid;
    728733
    729734                /* answer from server */
     
    732737                while( ( c = xt_find_node( c, "item" ) ) )
    733738                {
    734                         item = xt_find_attr( c, "name" );
    735739                        itemjid = xt_find_attr( c, "jid" );
    736 
    737                         jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );
     740                       
     741                        if( itemjid )
     742                                jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );
    738743
    739744                        c = c->next;
    740745                }
    741746        }
    742         else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 )
     747        else if( xmlns, XMLNS_DISCO_INFO ) == 0 )
    743748        {
    744749                char *category, *type;
     
    754759                        if( type && ( strcmp( type, "bytestreams" ) == 0 ) &&
    755760                            category && ( strcmp( category, "proxy" ) == 0 ) )
    756                                 jabber_iq_query_server( ic, xt_find_attr( node, "from" ), XMLNS_BYTESTREAMS );
     761                                jabber_iq_query_server( ic, from, XMLNS_BYTESTREAMS );
    757762
    758763                        c = c->next;
    759764                }
    760765        }
    761         else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_BYTESTREAMS ) == 0 )
    762         {
    763                 char *host, *jid;
     766        else if( xmlns, XMLNS_BYTESTREAMS ) == 0 )
     767        {
     768                char *host, *jid, *port_s;
    764769                int port;
    765770
     
    768773                if( ( c = xt_find_node( c->children, "streamhost" ) ) &&
    769774                    ( host = xt_find_attr( c, "host" ) ) &&
    770                     ( port = atoi( xt_find_attr( c, "port" ) ) ) &&
     775                    ( port_s = xt_find_attr( c, "port" ) ) &&
     776                    ( sscanf( port_s, "%d", &port ) == 1 ) &&
    771777                    ( jid = xt_find_attr( c, "jid" ) ) )
    772778                {
    773779                        jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 );
     780                       
    774781                        sh->jid = g_strdup( jid );
    775782                        sh->host = g_strdup( host );
    776                         sprintf( sh->port, "%u", port );
     783                        g_snprintf( sh->port, sizeof( sh->port ), "%u", port );
    777784
    778785                        imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port );
Note: See TracChangeset for help on using the changeset viewer.