Changeset 263

Show
Ignore:
Timestamp:
04/14/11 21:04:16 (13 months ago)
Author:
marek
Message:

ap51-flash: replace unreliable strlen() check by ip header length

Signed-off-by: Marek Lindner <lindner_marek@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ap51-flash-ng/proto.c

    r262 r263  
    551551{ 
    552552        struct tcphdr *tcphdr; 
     553        unsigned int data_len; 
    553554        char *buff; 
    554555 
     
    567568        if (tcphdr->ack != 1) 
    568569                goto out; 
     570 
     571        data_len = packet_buff_len - (tcphdr->doff * 4); 
    569572 
    570573        switch (node->tcp_state.status) { 
     
    585588                buff = (char *)(tcphdr + 1); 
    586589                node->tcp_state.status = TCP_STATUS_TELNET_READY; 
    587                 node->tcp_state.my_ack_seq += packet_buff_len - (int)sizeof(struct tcphdr); 
     590                node->tcp_state.my_ack_seq += data_len; 
    588591 
    589592                /* send CTRL + C */ 
     
    599602                if ((tcphdr->seq == node->tcp_state.his_seq) && 
    600603                    (tcphdr->ack_seq == node->tcp_state.his_ack_seq) && 
    601                     (strlen((char *)(tcphdr + 1)) == node->tcp_state.his_last_len)) { 
     604                    (data_len == node->tcp_state.his_last_len)) { 
    602605                        /* printf("retransmission received: seq = %u, ack_seq: %u, len: %u\n", 
    603                                ntohl(tcphdr->seq), ntohl(tcphdr->ack_seq), 
    604                                (unsigned int)strlen((char *)(tcphdr + 1))); */ 
     606                               ntohl(tcphdr->seq), ntohl(tcphdr->ack_seq), data_len); */ 
    605607                        tcp_resend_data(node); 
    606608                        goto out; 
     
    609611                node->tcp_state.his_seq = tcphdr->seq; 
    610612                node->tcp_state.his_ack_seq = tcphdr->ack_seq; 
    611                 node->tcp_state.his_last_len = strlen((char *)(tcphdr + 1)); 
     613                node->tcp_state.his_last_len = data_len; 
    612614 
    613615                if (node->tcp_state.his_last_len == 0) { 
     
    617619                } 
    618620 
    619                 node->tcp_state.my_ack_seq += packet_buff_len - (int)sizeof(struct tcphdr); 
     621                node->tcp_state.my_ack_seq += data_len; 
    620622                if (ntohl(tcphdr->ack_seq) > node->tcp_state.my_seq) 
    621623                        node->tcp_state.my_seq = ntohl(tcphdr->ack_seq); 
     
    634636{ 
    635637        struct iphdr *iphdr; 
     638        int length; 
    636639 
    637640        if (!len_check(packet_buff_len, sizeof(struct iphdr), "IPv4")) 
     
    671674                        break; 
    672675 
     676                length = packet_buff_len; 
     677                if (length > ntohs(iphdr->tot_len)) 
     678                        length = ntohs(iphdr->tot_len); 
     679 
    673680                handle_tcp_packet(packet_buff + (iphdr->ihl * 4), 
    674                                   packet_buff_len - (iphdr->ihl * 4), 
    675                                   node); 
     681                                  length - (iphdr->ihl * 4), node); 
    676682                break; 
    677683        } 
     
    709715                if (!node) 
    710716                        return; 
     717 
    711718                handle_ip_packet(packet_buff + ETH_HLEN, 
    712719                                 packet_buff_len - ETH_HLEN,