Changeset a8a9355 for lib/trace.c


Ignore:
Timestamp:
10/27/05 14:54:51 (16 years ago)
Author:
Perry Lorier <perry@…>
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:
779d445
Parents:
953c53f
Message:

Add assert()'s to catch if you call functions after the end of file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r7c8eacf ra8a9355  
    508508
    509509        if (libtrace->format->read_packet) {
    510                 return libtrace->format->read_packet(libtrace,packet);
    511         }
     510                return (packet->size=libtrace->format->read_packet(libtrace,packet));
     511        }
     512        packet->size=-1;
    512513        return -1;
    513514}
     
    524525        assert(libtrace);
    525526        assert(packet);
     527        /* Verify the packet is valid */
     528        assert(packet->size<65536);
     529        assert(packet->size>0);
    526530
    527531        if (libtrace->format->write_packet) {
     
    540544void *trace_get_link(const struct libtrace_packet_t *packet) {
    541545        const void *ethptr = 0;
     546
     547        assert(packet->size>0 && packet->size<65536);
    542548       
    543549        if (packet->trace->format->get_link) {
     
    774780        struct libtrace_udp *udpptr = 0;
    775781
    776         if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
     782        if ((ip->ip_p == 17) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
    777783                udpptr = (struct libtrace_udp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
    778784        }
     
    884890        struct timeval ts;
    885891
     892        assert(packet->size>0 && packet->size<65536);
     893
    886894        if (packet->trace->format->get_erf_timestamp) {
    887895                // timestamp -> timestamp
     
    912920        uint64_t ts = 0;
    913921        double seconds = 0.0;
     922        assert(packet->size>0 && packet->size<65536);
    914923        if (packet->trace->format->get_timeval) {
    915924                // timeval -> timeval
     
    951960        uint64_t ts = 0;
    952961        struct timeval tv;
     962
     963        assert(packet->size>0 && packet->size<65536);
    953964       
    954965        if (packet->trace->format->get_seconds) {
     
    984995int trace_get_capture_length(const struct libtrace_packet_t *packet) {
    985996
     997        assert(packet->size>0 && packet->size<65536);
     998
    986999        if (packet->trace->format->get_capture_length) {
    9871000                return packet->trace->format->get_capture_length(packet);
     
    10001013 */
    10011014int trace_get_wire_length(const struct libtrace_packet_t *packet){
     1015        assert(packet->size>0 && packet->size<65536);
     1016
    10021017        if (packet->trace->format->get_wire_length) {
    10031018                return packet->trace->format->get_wire_length(packet);
     
    12041219int8_t trace_set_direction(struct libtrace_packet_t *packet, int8_t direction) {
    12051220        assert(packet);
     1221        assert(packet->size>0 && packet->size<65536);
    12061222        if (packet->trace->format->set_direction) {
    12071223                return packet->trace->format->set_direction(packet,direction);
     
    12211237int8_t trace_get_direction(const struct libtrace_packet_t *packet) {
    12221238        assert(packet);
     1239        assert(packet->size>0 && packet->size<65536);
    12231240        if (packet->trace->format->get_direction) {
    12241241                return packet->trace->format->get_direction(packet);
     
    13941411size_t trace_set_capture_length(struct libtrace_packet_t *packet, size_t size) {
    13951412        assert(packet);
     1413        assert(packet->size>0 && packet->size<65536);
    13961414
    13971415        if (packet->trace->format->set_capture_length) {
Note: See TracChangeset for help on using the changeset viewer.