In a Simple Packet Block, the captured length isn't the block length
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 28 Sep 2013 18:03:20 +0000 (18:03 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 28 Sep 2013 18:03:20 +0000 (18:03 +0000)
minus the lengths of the two length fields and the packet length field,
it's the minimum of that and the packet length, as there might be
padding.

Fixes one problem found by the file in bug 9200.

While we're at it, pcapng_read_packet_block() and
pcapng_read_simple_packet_block() return an integer, not a Boolean;
return 0, not FALSE (they have the same value, but returning 0 makes it
clearer that the return value isn't restricted to TRUE or FALSE).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@52241 f5534014-38df-0310-8fa8-9805f1628bb7

wiretap/pcapng.c

index a657207bac11be86ba6b29466861b71847dbc467..b0fc3c2dc9a861d9d125850b96451da9fa4846a7 100644 (file)
@@ -1114,7 +1114,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
                 *err = WTAP_ERR_BAD_FILE;
                 *err_info = g_strdup_printf("pcapng: interface index %u is not less than interface count %u.",
                     wblock->data.packet.interface_id, pn->number_of_interfaces);
-                return FALSE;
+                return 0;
         }
         int_data = g_array_index(pn->interface_data, interface_data_t,
             wblock->data.packet.interface_id);
@@ -1138,7 +1138,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
                                                        err,
                                                        err_info);
         if (pseudo_header_len < 0) {
-                return FALSE;
+                return 0;
         }
         block_read += pseudo_header_len;
         if (pseudo_header_len != pcap_get_phdr_size(int_data.wtap_encap, &wblock->packet_header->pseudo_header)) {
@@ -1157,7 +1157,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
         errno = WTAP_ERR_CANT_READ;
        if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
            wblock->data.packet.cap_len - pseudo_header_len, err, err_info))
-               return FALSE;
+               return 0;
         block_read += wblock->data.packet.cap_len - pseudo_header_len;
 
         /* jump over potential padding bytes at end of the packet data */
@@ -1338,6 +1338,8 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
         wblock->data.simple_packet.cap_len = bh->block_total_length
                                              - (guint32)sizeof(pcapng_simple_packet_block_t)
                                              - (guint32)sizeof(bh->block_total_length);
+        if (wblock->data.simple_packet.cap_len > wblock->data.simple_packet.packet_len)
+                wblock->data.simple_packet.cap_len = wblock->data.simple_packet.packet_len;
 
         if (wblock->data.simple_packet.cap_len > WTAP_MAX_PACKET_SIZE) {
                 *err = WTAP_ERR_BAD_FILE;
@@ -1352,7 +1354,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
                 *err = WTAP_ERR_BAD_FILE;
                 *err_info = g_strdup_printf("pcapng: interface index 0 is not less than interface count %u.",
                     pn->number_of_interfaces);
-                return FALSE;
+                return 0;
         }
         int_data = g_array_index(pn->interface_data, interface_data_t, 0);
 
@@ -1396,7 +1398,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
         errno = WTAP_ERR_CANT_READ;
        if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
            wblock->data.simple_packet.cap_len, err, err_info))
-               return FALSE;
+               return 0;
         block_read += wblock->data.simple_packet.cap_len;
 
         /* jump over potential padding bytes at end of the packet data */