Ignore:
Timestamp:
01/19/10 15:35:02 (3 years ago)
Author:
salcock
Message:
  • Fixed bug where a packet with zero bytes of payload would result in pcapfile_read_packet returning an EOF indicator.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/format_pcapfile.c

    r1443 r1490  
    279279        int err; 
    280280        uint32_t flags = 0; 
    281          
     281        size_t bytes_to_read = 0; 
     282 
    282283        assert(libtrace->format_data); 
    283284 
     
    303304                return 0; 
    304305        } 
    305          
    306         assert(swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen)<LIBTRACE_PACKET_BUFSIZE); 
    307  
     306 
     307        bytes_to_read = swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen); 
     308 
     309        assert(bytes_to_read < LIBTRACE_PACKET_BUFSIZE); 
     310 
     311        /* If there is no payload to read, do not ask wandio_read to try and 
     312         * read zero bytes - we'll just get back a zero that we will  
     313         * misinterpret as EOF! */ 
     314        if (bytes_to_read == 0) { 
     315                return sizeof(libtrace_pcapfile_pkt_hdr_t); 
     316        } 
    308317 
    309318        err=wandio_read(libtrace->io, 
     
    326335        } 
    327336         
    328         return sizeof(libtrace_pcapfile_pkt_hdr_t) 
    329                 +swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen); 
     337        return sizeof(libtrace_pcapfile_pkt_hdr_t) + bytes_to_read; 
    330338} 
    331339 
Note: See TracChangeset for help on using the changeset viewer.