Do a check of the block total length in pcapng_read_unknown_block().
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 23 Feb 2012 10:03:16 +0000 (10:03 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 23 Feb 2012 10:03:16 +0000 (10:03 +0000)
That means we don't need to do the block length check in
pcapng_read_block(); each block type reader, including the one for
unknown block types, does a check that's as stringent as that block
length check or more stringent, which means any block whose length is
less than the minimum will fail with the same error in both cases.

Fix the message for a too-short NRB.

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

wiretap/pcapng.c

index c81b0e2..65ad35c 100644 (file)
@@ -1347,7 +1347,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t
                 * No.
                 */
                *err = WTAP_ERR_BAD_FILE;
-               *err_info = g_strdup_printf("pcapng_read_name_resolution_block: total block length %u is too small (< %u)",
+               *err_info = g_strdup_printf("pcapng_read_name_resolution_block: total block length %u of an NRB is less than the minimum NRB size %u",
                              bh->block_total_length, MIN_NRB_SIZE);
                return -1;
        }
@@ -1662,12 +1662,18 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
 
 
 static int
-pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn _U_, wtapng_block_t *wblock _U_,int *err, gchar **err_info _U_)
+pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn _U_, wtapng_block_t *wblock _U_, int *err, gchar **err_info)
 {
        int block_read;
        guint64 file_offset64;
        guint32 block_total_length;
 
+       if (bh->block_total_length < MIN_BLOCK_SIZE) {
+               *err = WTAP_ERR_BAD_FILE;
+               *err_info = g_strdup_printf("pcapng_read_unknown_block: total block length %u of an unknown block type is less than the minimum block size %u",
+                             bh->block_total_length, MIN_BLOCK_SIZE);
+               return -1;
+       }
 
        /* add padding bytes to "block total length" */
        /* (the "block total length" of some example files don't contain any padding bytes!) */
@@ -1735,19 +1741,6 @@ pcapng_read_block(FILE_T fh, gboolean first_block, pcapng_t *pn, wtapng_block_t
                        return 0;       /* not a pcap-ng file */
        }
 
-       if (bh.block_total_length < MIN_BLOCK_SIZE) {
-               /*
-                * This isn't even enough for the block type and 2
-                * block total length fields.
-                */
-               if (first_block)
-                       return 0;       /* probably not a pcap-ng file */
-               *err = WTAP_ERR_BAD_FILE;
-               *err_info = g_strdup_printf("pcapng_read_block: total block length %u is too small (< %u)",
-                             bh.block_total_length, (guint32)MIN_BLOCK_SIZE);
-               return -1;
-       }
-
        switch(bh.block_type) {
                case(BLOCK_TYPE_SHB):
                        bytes_read = pcapng_read_section_header_block(fh, first_block, &bh, pn, wblock, err, err_info);