If a gzipped file's name ends in .caz, don't check the CRC - it's
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 9 May 2011 03:48:41 +0000 (03:48 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 9 May 2011 03:48:41 +0000 (03:48 +0000)
probably a compressed file from the Windows Sniffer, and they don't
bother setting the CRC.

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

wiretap/file_access.c
wiretap/file_wrappers.c

index 7df57d933e72b255527e24e7b305e9b6dcfc78aa..ed213e6df84f2403e6fe755367a74534857c12b2 100644 (file)
@@ -293,7 +293,7 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
        if (use_stdin) {
                /*
                 * We dup FD 0, so that we don't have to worry about
-                * an fclose or gzclose of wth->fh closing the standard
+                * a file_close of wth->fh closing the standard
                 * input of the process.
                 */
                wth->fd = ws_dup(0);
@@ -310,20 +310,19 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
                        return NULL;
                }
 #endif
+               if (!(wth->fh = filed_open(wth->fd))) {
+                       *err = errno;
+                       ws_close(wth->fd);
+                       g_free(wth);
+                       return NULL;
+               }
        } else {
-               wth->fd = ws_open(filename, O_RDONLY|O_BINARY, 0000 /* no creation so don't matter */);
-               if (wth->fd < 0) {
+               if (!(wth->fh = file_open(filename))) {
                        *err = errno;
                        g_free(wth);
                        return NULL;
                }
        }
-       if (!(wth->fh = filed_open(wth->fd))) {
-               *err = errno;
-               ws_close(wth->fd);
-               g_free(wth);
-               return NULL;
-       }
 
        if (do_random) {
                if (!(wth->random_fh = file_open(filename))) {
index 8beaf6674c31b30ec5de395d54e613d7bae2e4e4..681878bd7e4881d4bc041e6d8b21ace03d870341 100644 (file)
@@ -98,6 +98,7 @@ struct wtap_reader {
 #ifdef HAVE_LIBZ
        /* zlib inflate stream */
        z_stream strm;          /* stream structure in-place (not a pointer) */
+       int dont_check_crc;     /* 1 if we aren't supposed to check the CRC */
 #endif
        /* fast seeking */
        GPtrArray *fast_seek;
@@ -505,7 +506,7 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count)
        if (ret == Z_STREAM_END) {
                if (gz_next4(state, &crc) != -1 &&
                    gz_next4(state, &len) != -1) {
-                       if (crc != strm->adler) {
+                       if (crc != strm->adler && !state->dont_check_crc) {
                                state->err = WTAP_ERR_DECOMPRESS;
                                state->err_info = "bad CRC";
                        } else if (len != (strm->total_out & 0xffffffffL)) {
@@ -785,6 +786,9 @@ filed_open(int fd)
                errno = ENOMEM;
                return NULL;
        }
+
+       /* for now, assume we should check the crc */
+       state->dont_check_crc = 0;
 #endif
        /* return stream */
        return state;
@@ -795,6 +799,9 @@ file_open(const char *path)
 {
        int fd;
        FILE_T ft;
+#ifdef HAVE_LIBZ
+       const char *suffixp;
+#endif
 
        /* open file and do correct filename conversions.
 
@@ -805,7 +812,7 @@ file_open(const char *path)
           here.  Pre-Large File Summit UN*Xes, and possibly even some
           post-LFS UN*Xes, might require O_LARGEFILE here, though.
           If so, we should probably handle that in ws_open(). */
-       if ((fd = ws_open(path, O_RDONLY|O_BINARY, 0666)) == -1)
+       if ((fd = ws_open(path, O_RDONLY|O_BINARY, 0000)) == -1)
                return NULL;
 
        /* open file handle */
@@ -815,6 +822,19 @@ file_open(const char *path)
                return NULL;
        }
 
+#ifdef HAVE_LIBZ
+       /*
+        * If this file's name ends in ".caz", it's probably a compressed
+        * Windows Sniffer file.  The compression is gzip, but they don't
+        * bother filling in the CRC; we set a flag to ignore CRC errors.
+        */
+       suffixp = strrchr(path, '.');
+       if (suffixp != NULL) {
+               if (g_ascii_strcasecmp(suffixp, ".caz") == 0)
+                       ft->dont_check_crc = 1;
+       }
+#endif
+
        return ft;
 }