Changeset c2afda6


Ignore:
Timestamp:
01/21/10 10:10:46 (11 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
1481ba7
Parents:
b5a23b3
Message:
  • Adjusted the "shortcut" protocol access functions to return NULL if a full header (minus options) is not present.
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/protocols_l3.c

    r59751a5 rc2afda6  
    4747
    4848        if (!ret || ethertype!=TRACE_ETHERTYPE_IPV6)
     49                return NULL;
     50
     51        /* Make sure we have at least the base IPv6 header */
     52        if (remaining < sizeof(libtrace_ip6_t))
    4953                return NULL;
    5054
     
    247251                                           * with these packets
    248252                                           */
     253
     254                        /* Ensure that optlen is not greater than the
     255                         * amount of buffer remaining */
     256                        if (*optlen > *len)
     257                                return 0;
     258                       
    249259                        (*len)-=*optlen;
    250260                        (*data)=(*ptr+2);
  • lib/protocols_transport.c

    rf0fa090 rc2afda6  
    4646DLLEXPORT libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet) {
    4747        uint8_t proto;
     48        uint32_t rem = 0;
    4849        libtrace_tcp_t *tcp;
    4950
    50         tcp=(libtrace_tcp_t*)trace_get_transport(packet,&proto,NULL);
     51        tcp=(libtrace_tcp_t*)trace_get_transport(packet,&proto,&rem);
    5152
    5253        if (!tcp || proto != TRACE_IPPROTO_TCP)
     54                return NULL;
     55
     56        /* We should return NULL if there isn't a full TCP header, because the
     57         * caller has no way of telling how much of a TCP header we have
     58         * returned - use trace_get_transport() if you want to deal with
     59         * partial headers
     60         *
     61         * NOTE: We're not going to insist that all the TCP options are present
     62         * as well, because lots of traces are snapped after 20 bytes of TCP
     63         * header and I don't really want to break libtrace programs that
     64         * use this function to process those traces */
     65
     66        if (rem < sizeof(libtrace_tcp_t))
    5367                return NULL;
    5468
     
    7084DLLEXPORT libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet) {
    7185        uint8_t proto;
     86        uint32_t rem = 0;
    7287        libtrace_udp_t *udp;
    7388
    74         udp=(libtrace_udp_t*)trace_get_transport(packet,&proto,NULL);
     89        udp=(libtrace_udp_t*)trace_get_transport(packet,&proto,&rem);
    7590
    7691        if (!udp || proto != TRACE_IPPROTO_UDP)
     92                return NULL;
     93
     94        /* Make sure we return a full UDP header as the caller has no way of
     95         * telling how much of the packet is remaining */
     96        if (rem < sizeof(libtrace_udp_t))
    7797                return NULL;
    7898
     
    94114DLLEXPORT libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet) {
    95115        uint8_t proto;
     116        uint32_t rem = 0;
    96117        libtrace_icmp_t *icmp;
    97118
    98         icmp=(libtrace_icmp_t*)trace_get_transport(packet,&proto,NULL);
     119        icmp=(libtrace_icmp_t*)trace_get_transport(packet,&proto,&rem);
    99120
    100121        if (!icmp || proto != TRACE_IPPROTO_ICMP)
     122                return NULL;
     123
     124        /* Make sure we return a full ICMP header as the caller has no way of
     125         * telling how much of the packet is remaining */
     126        if (rem < sizeof(libtrace_icmp_t))
    101127                return NULL;
    102128
Note: See TracChangeset for help on using the changeset viewer.