diff options
43 files changed, 332 insertions, 324 deletions
diff --git a/wiretap/5views.c b/wiretap/5views.c index 9629c2e691..1b0a54c701 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -126,7 +126,7 @@ int _5views_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&Capture_Header.Info_Header, sizeof(t_5VW_Info_Header), wth->fh); if (bytes_read != sizeof(t_5VW_Info_Header)) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -180,9 +180,9 @@ int _5views_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&Capture_Header.HeaderDateCreation, sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), wth->fh); if (bytes_read != sizeof (t_5VW_Capture_Header)- sizeof(t_5VW_Info_Header) ) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* This is a 5views capture file */ diff --git a/wiretap/aethra.c b/wiretap/aethra.c index 6220fecf40..d04bf8d875 100644 --- a/wiretap/aethra.c +++ b/wiretap/aethra.c @@ -136,7 +136,7 @@ int aethra_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(hdr.magic, sizeof hdr.magic, wth->fh); if (bytes_read != sizeof hdr.magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -150,9 +150,9 @@ int aethra_open(wtap *wth, int *err, gchar **err_info) sizeof hdr - sizeof hdr.magic, wth->fh); if (bytes_read != sizeof hdr - sizeof hdr.magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } wth->file_type = WTAP_FILE_AETHRA; aethra = (aethra_t *)g_malloc(sizeof(aethra_t)); diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index 1a77ea427e..cace17ed4f 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -148,12 +148,11 @@ static gint64 ascend_seek(wtap *wth, int *err, gchar **err_info) } } - if (byte != EOF || file_eof(wth->fh)) { - /* Either we didn't find the offset, or we got an EOF. */ + if (byte != EOF) { + /* We didn't find the offset. Treat that as a "not an Ascend file" + indication. */ *err = 0; } else { - /* We (presumably) got an error (there's no equivalent to "ferror()" - in zlib, alas, so we don't have a wrapper to check for an error). */ *err = file_error(wth->fh, err_info); } return -1; @@ -187,10 +186,9 @@ int ascend_open(wtap *wth, int *err, gchar **err_info) offset = ascend_seek(wth, err, err_info); if (offset == -1) { - if (*err == 0) - return 0; - else + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; + return 0; } /* Do a trial parse of the first packet just found to see if we might really have an Ascend file */ diff --git a/wiretap/ber.c b/wiretap/ber.c index 3dfe78b462..990db1de73 100644 --- a/wiretap/ber.c +++ b/wiretap/ber.c @@ -131,7 +131,9 @@ int ber_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&bytes, BER_BYTES_TO_CHECK, wth->fh); if (bytes_read != BER_BYTES_TO_CHECK) { *err = file_error(wth->fh, err_info); - return (*err != 0) ? -1 : 0; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } ber_id = bytes[offset++]; diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index baa8812214..3666cbb68b 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -92,7 +92,7 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -106,9 +106,9 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* diff --git a/wiretap/commview.c b/wiretap/commview.c index 5fe51ea8b5..935d15f01b 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -96,11 +96,9 @@ int commview_open(wtap *wth, int *err, gchar **err_info) commview_header_t cv_hdr; if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) { - if (*err == 0 || *err == WTAP_ERR_SHORT_READ) { - /* This just means "not CommView" */ - return 0; - } - return -1; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } /* If any of these fields do not match what we expect, bail out. */ diff --git a/wiretap/cosine.c b/wiretap/cosine.c index b2ad78daf4..f0d67306c7 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -253,26 +253,22 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info) buf[COSINE_LINE_LENGTH-1] = '\0'; for (line = 0; line < COSINE_HEADER_LINES_TO_CHECK; line++) { - if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) != NULL) { - - reclen = strlen(buf); - if (reclen < strlen(COSINE_HDR_MAGIC_STR1) || - reclen < strlen(COSINE_HDR_MAGIC_STR2)) { - continue; - } - - if (strstr(buf, COSINE_HDR_MAGIC_STR1) || - strstr(buf, COSINE_HDR_MAGIC_STR2)) { - return TRUE; - } - } else { + if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) == NULL) { /* EOF or error. */ - if (file_eof(wth->fh)) - *err = 0; - else - *err = file_error(wth->fh, err_info); + *err = file_error(wth->fh, err_info); return FALSE; } + + reclen = strlen(buf); + if (reclen < strlen(COSINE_HDR_MAGIC_STR1) || + reclen < strlen(COSINE_HDR_MAGIC_STR2)) { + continue; + } + + if (strstr(buf, COSINE_HDR_MAGIC_STR1) || + strstr(buf, COSINE_HDR_MAGIC_STR2)) { + return TRUE; + } } *err = 0; return FALSE; @@ -283,10 +279,9 @@ int cosine_open(wtap *wth, int *err, gchar **err_info) { /* Look for CoSine header */ if (!cosine_check_file_type(wth, err, err_info)) { - if (*err == 0) - return 0; - else + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; + return 0; } if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */ diff --git a/wiretap/csids.c b/wiretap/csids.c index 9555e005da..08f60f05ea 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -79,11 +79,10 @@ int csids_open(wtap *wth, int *err, gchar **err_info) bytesRead = file_read( &hdr, sizeof( struct csids_header), wth->fh ); if( bytesRead != sizeof( struct csids_header) ) { *err = file_error( wth->fh, err_info ); - if( *err != 0 ) { + if( *err != 0 && *err != WTAP_ERR_SHORT_READ ) { return -1; - } else { - return 0; } + return 0; } if( hdr.zeropad != 0 || hdr.caplen == 0 ) { return 0; @@ -93,25 +92,23 @@ int csids_open(wtap *wth, int *err, gchar **err_info) bytesRead = file_read( &tmp, 2, wth->fh ); if( bytesRead != 2 ) { *err = file_error( wth->fh, err_info ); - if( *err != 0 ) { + if( *err != 0 && *err != WTAP_ERR_SHORT_READ ) { return -1; - } else { - return 0; } + return 0; } bytesRead = file_read( &iplen, 2, wth->fh ); if( bytesRead != 2 ) { *err = file_error( wth->fh, err_info ); - if( *err != 0 ) { + if( *err != 0 && *err != WTAP_ERR_SHORT_READ ) { return -1; - } else { - return 0; } + return 0; } iplen = pntohs(&iplen); if ( iplen == 0 ) - return(0); + return 0; /* if iplen and hdr.caplen are equal, default to no byteswap. */ if( iplen > hdr.caplen ) { diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index 47d1475eee..8fdfdb71de 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -90,13 +90,18 @@ static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, static guint daintree_sna_hex_char(guchar *str, int *err); /* Open a file and determine if it's a Daintree file */ -int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_) +int daintree_sna_open(wtap *wth, int *err, gchar **err_info) { char readLine[DAINTREE_MAX_LINE_SIZE]; guint i; /* get first line of file header */ - if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) return 0; + if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } /* check magic text */ i = 0; @@ -106,7 +111,12 @@ int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_) } /* read second header line */ - if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) return 0; + if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } if (readLine[0] != COMMENT_LINE) return 0; /* daintree files have a two line header */ /* set up the pointers to the handlers for this file type */ diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index 6a276045ef..5a46686326 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -193,10 +193,9 @@ int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info) { /* Look for DBS ETHERWATCH header */ if (!dbs_etherwatch_check_file_type(wth, err, err_info)) { - if (*err == 0) - return 0; - else + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; + return 0; } wth->file_encap = WTAP_ENCAP_ETHERNET; diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index 9bbae29cfc..ecc466863d 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -156,49 +156,25 @@ xml_get_int(int *val, const unsigned char *str, const unsigned char *pattern) } -/* Look through the first part of a file to see if this is - * a DCT3 trace file. - * - * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value - * and "*err_info" will be set to null or an additional error string. - */ -static gboolean dct3trace_check_file_type(wtap *wth, int *err, gchar **err_info) +int dct3trace_open(wtap *wth, int *err, gchar **err_info) { char line1[64], line2[64]; - if (file_gets(line1, sizeof(line1), wth->fh) != NULL && - file_gets(line2, sizeof(line2), wth->fh) != NULL) - { - /* Don't compare line endings */ - if( strncmp(dct3trace_magic_line1, line1, strlen(dct3trace_magic_line1)) == 0 && - strncmp(dct3trace_magic_line2, line2, strlen(dct3trace_magic_line2)) == 0) - { - return TRUE; - } - } - /* EOF or error. */ - else + /* Look for Gammu DCT3 trace header */ + if (file_gets(line1, sizeof(line1), wth->fh) == NULL || + file_gets(line2, sizeof(line2), wth->fh) == NULL) { - if (file_eof(wth->fh)) - *err = 0; - else - *err = file_error(wth->fh, err_info); + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } - return FALSE; -} - - -int dct3trace_open(wtap *wth, int *err, gchar **err_info) -{ - /* Look for Gammu DCT3 trace header */ - if (!dct3trace_check_file_type(wth, err, err_info)) + /* Don't compare line endings */ + if( strncmp(dct3trace_magic_line1, line1, strlen(dct3trace_magic_line1)) != 0 || + strncmp(dct3trace_magic_line2, line2, strlen(dct3trace_magic_line2)) != 0) { - if (*err == 0) - return 0; - else - return -1; + return 0; } wth->file_encap = WTAP_ENCAP_GSM_UM; diff --git a/wiretap/erf.c b/wiretap/erf.c index b64c009260..d0a443c3e2 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -124,7 +124,8 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info) if (r == 0 ) break; if (r != sizeof(header)) { - if ((*err = file_error(wth->fh, err_info)) != 0) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) { return -1; } else { /* ERF header too short accept the file, @@ -195,6 +196,8 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info) while (type & 0x80){ if (file_read(&erf_ext_header, sizeof(erf_ext_header),wth->fh) != sizeof(erf_ext_header)) { *err = file_error(wth->fh, err_info); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; return -1; } packet_size -= (guint32)sizeof(erf_ext_header); diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index dcf5e5565e..fc25ad344b 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -141,7 +141,7 @@ int eyesdn_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index 21a7d11e65..50c37c17c6 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -128,7 +128,9 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh); if (bytes_read != DUMP_HDR_SIZE) { *err = file_error(wth->fh, err_info); - return (*err != 0) ? -1 : 0; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } if ((dh.in != 0 && dh.in != 1) || dh.pad != 0 @@ -138,7 +140,9 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&type, 1, wth->fh); if (bytes_read != 1) { *err = file_error(wth->fh, err_info); - return (*err != 0) ? -1 : 0; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } if (type < 1 || type > 4) diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 6ce3dab1e1..79336f2ec2 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -68,7 +68,7 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&hdr, sizeof(hdr), wth->fh); if (bytes_read != sizeof(hdr)) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index 5120854716..9a656808bd 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -197,7 +197,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) *err_info = NULL; return 0; } - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; /* real failure */ /* else it's EOF */ if (i < 1) { diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index a2b8ec5feb..1c46890ab6 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -59,11 +59,11 @@ int iptrace_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(name, 11, wth->fh); if (bytes_read != 11) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } - name[11] = 0; + name[11] = '\0'; if (strcmp(name, "iptrace 1.0") == 0) { wth->file_type = WTAP_FILE_IPTRACE_1_0; diff --git a/wiretap/iseries.c b/wiretap/iseries.c index eedb2ef1ff..4603647540 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -218,7 +218,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info) if (bytes_read != sizeof magic) { *err = file_error (wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -327,47 +327,44 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) for (line = 0; line < ISERIES_HDR_LINES_TO_CHECK; line++) { - if (file_gets (buf, ISERIES_LINE_LENGTH, wth->fh) != NULL) - { - /* - * Check that we are dealing with an ETHERNET trace - */ - if (iseries->format == ISERIES_FORMAT_UNICODE) - { - iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); - } - ascii_strup_inplace (buf); - num_items_scanned = sscanf (buf, - "%*[ \n\t]OBJECT PROTOCOL%*[ .:\n\t]%8s", - protocol); - if (num_items_scanned == 1) - { - if (memcmp (protocol, "ETHERNET", 8) != 0) - return FALSE; - } - - /* - * The header is the only place where the date part of the timestamp is held, so - * extract it here and store for all packets to access - */ - num_items_scanned = sscanf (buf, - "%*[ \n\t]START DATE/TIME%*[ .:\n\t]%2d/%2d/%2d", - &iseries->month, &iseries->day, - &iseries->year); - if (num_items_scanned == 3) - { - iseries->have_date = TRUE; - } - } - else + if (file_gets (buf, ISERIES_LINE_LENGTH, wth->fh) == NULL) { /* EOF or error. */ - if (file_eof (wth->fh)) + *err = file_error (wth->fh, err_info); + if (*err == WTAP_ERR_SHORT_READ) *err = 0; - else - *err = file_error (wth->fh, err_info); return FALSE; } + + /* + * Check that we are dealing with an ETHERNET trace + */ + if (iseries->format == ISERIES_FORMAT_UNICODE) + { + iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); + } + ascii_strup_inplace (buf); + num_items_scanned = sscanf (buf, + "%*[ \n\t]OBJECT PROTOCOL%*[ .:\n\t]%8s", + protocol); + if (num_items_scanned == 1) + { + if (memcmp (protocol, "ETHERNET", 8) != 0) + return FALSE; + } + + /* + * The header is the only place where the date part of the timestamp is held, so + * extract it here and store for all packets to access + */ + num_items_scanned = sscanf (buf, + "%*[ \n\t]START DATE/TIME%*[ .:\n\t]%2d/%2d/%2d", + &iseries->month, &iseries->day, + &iseries->year); + if (num_items_scanned == 3) + { + iseries->have_date = TRUE; + } } *err = 0; return TRUE; diff --git a/wiretap/k12.c b/wiretap/k12.c index eba4d4e25f..9c4b526f0e 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -696,7 +696,7 @@ int k12_open(wtap *wth, int *err, gchar **err_info) { if ( file_read(header_buffer,0x200,wth->fh) != 0x200 ) { K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR")); *err = file_error(wth->fh, err_info); - if (*err != 0) { + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) { return -1; } return 0; diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 7798b3f3f8..f4c474ab17 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -290,7 +290,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wth->fh); if (bytes_read != LA_RecordHeaderSize) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -303,18 +303,18 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) /* Read the major and minor version numbers */ if (record_length < 2) { - /* Not enough room for the major and minor version numbers. */ - *err = WTAP_ERR_BAD_FILE; - *err_info = g_strdup_printf("lanalyzer: trace header record length %u < 2", - record_length); - return -1; + /* + * Not enough room for the major and minor version numbers. + * Just treat that as a "not a LANalyzer file" indication. + */ + return 0; } bytes_read = file_read(&header_fixed, sizeof header_fixed, wth->fh); if (bytes_read != sizeof header_fixed) { *err = file_error(wth->fh, err_info); - if (*err == 0) - *err = WTAP_ERR_SHORT_READ; - return -1; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } record_length -= sizeof header_fixed; @@ -324,9 +324,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(comment, record_length, wth->fh); if (bytes_read != record_length) { *err = file_error(wth->fh, err_info); - if (*err == 0) - *err = WTAP_ERR_SHORT_READ; - return -1; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } comment[record_length] = '\0'; wth->shb_hdr.opt_comment = comment; @@ -349,12 +349,11 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wth->fh); if (bytes_read != LA_RecordHeaderSize) { *err = file_error(wth->fh, err_info); - if (*err != 0) { - g_free(wth->priv); - return -1; - } + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; g_free(wth->priv); - return 0; + wth->priv = NULL; + return -1; } record_type = pletohs(rec_header.record_type); @@ -369,12 +368,11 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) wth->fh); if (bytes_read != sizeof summary) { *err = file_error(wth->fh, err_info); - if (*err != 0) { - g_free(wth->priv); - return -1; - } + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; g_free(wth->priv); - return 0; + wth->priv = NULL; + return -1; } /* Assume that the date of the creation of the trace file @@ -415,6 +413,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) break; default: g_free(wth->priv); + wth->priv = NULL; *err = WTAP_ERR_UNSUPPORTED_ENCAP; *err_info = g_strdup_printf("lanalyzer: board type %u unknown", board_type); @@ -428,6 +427,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) * can read this header */ if (file_seek(wth->fh, -LA_RecordHeaderSize, SEEK_CUR, err) == -1) { g_free(wth->priv); + wth->priv = NULL; return -1; } return 1; @@ -435,6 +435,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) default: if (file_seek(wth->fh, record_length, SEEK_CUR, err) == -1) { g_free(wth->priv); + wth->priv = NULL; return -1; } break; diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index 64df307385..018a35dbd3 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -95,7 +95,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -165,9 +165,9 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } if (byte_swapped) { diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c index 6c76ad82ba..61341ee662 100644 --- a/wiretap/mime_file.c +++ b/wiretap/mime_file.c @@ -146,7 +146,8 @@ mime_file_open(wtap *wth, int *err, gchar **err_info) { char magic_buf[128]; /* increase buffer size when needed */ int bytes_read; - int ret; + gboolean found_file; + /* guint file_ok; */ guint i; guint read_bytes = 0; @@ -157,40 +158,39 @@ mime_file_open(wtap *wth, int *err, gchar **err_info) read_bytes = (guint)MIN(read_bytes, sizeof(magic_buf)); bytes_read = file_read(magic_buf, read_bytes, wth->fh); - if (bytes_read > 0) { - gboolean found_file = FALSE; - /* guint file_ok; */ - - for (i = 0; i < N_MAGIC_TYPES; i++) { - if ((guint) bytes_read >= magic_files[i].magic_len && !memcmp(magic_buf, magic_files[i].magic, MIN(magic_files[i].magic_len, (guint) bytes_read))) { - if (!found_file) { - found_file = TRUE; - /* file_ok = i; */ - } else - return 0; /* many files matched, bad file */ - } + if (bytes_read < 0) { + *err = file_error(wth->fh, err_info); + return -1; + } + if (bytes_read == 0) + return 0; + + found_file = FALSE; + for (i = 0; i < N_MAGIC_TYPES; i++) { + if ((guint) bytes_read >= magic_files[i].magic_len && !memcmp(magic_buf, magic_files[i].magic, MIN(magic_files[i].magic_len, (guint) bytes_read))) { + if (!found_file) { + found_file = TRUE; + /* file_ok = i; */ + } else + return 0; /* many files matched, bad file */ } + } - if (!found_file) - return 0; + if (!found_file) + return 0; - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) - return -1; + if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) + return -1; - wth->file_type = WTAP_FILE_MIME; - wth->file_encap = WTAP_ENCAP_MIME; - wth->tsprecision = WTAP_FILE_TSPREC_SEC; - wth->subtype_read = mime_read; - wth->subtype_seek_read = mime_seek_read; - wth->snapshot_length = 0; - ret = 1; + wth->file_type = WTAP_FILE_MIME; + wth->file_encap = WTAP_ENCAP_MIME; + wth->tsprecision = WTAP_FILE_TSPREC_SEC; + wth->subtype_read = mime_read; + wth->subtype_seek_read = mime_seek_read; + wth->snapshot_length = 0; - wth->priv = g_malloc0(sizeof(mime_file_private_t)); + wth->priv = g_malloc0(sizeof(mime_file_private_t)); - } else { - *err = file_error(wth->fh, err_info); - ret = -1; - } - return ret; + return 1; } diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index 1ef731e49c..84964375ba 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -155,7 +155,9 @@ mp2t_open(wtap *wth, int *err, gchar **err_info) if (MP2T_SIZE != bytes_read) { *err = file_error(wth->fh, err_info); - return (*err == 0) ? 0 : -1; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } first = -1; @@ -175,8 +177,10 @@ mp2t_open(wtap *wth, int *err, gchar **err_info) /* read some packets and make sure they all start with a sync byte */ do { bytes_read = file_read(buffer, MP2T_SIZE+trailer_len, wth->fh); - if (bytes_read < 0) + if (bytes_read < 0) { + *err = file_error(wth->fh, err_info); return -1; /* read error */ + } if (bytes_read < MP2T_SIZE+trailer_len) { if(sync_steps<2) return 0; /* wrong file type - not an mpeg2 ts file */ break; /* end of file, that's ok if we're still in sync */ diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index 9d6640ea60..dfb8dd6846 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -270,7 +270,7 @@ mpeg_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(magic_buf, sizeof magic_buf, wth->fh); if (bytes_read != (int) sizeof magic_buf) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } diff --git a/wiretap/netmon.c b/wiretap/netmon.c index 3c388e2fa7..f48c564ff9 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -43,14 +43,17 @@ /* Capture file header, *including* magic number, is padded to 128 bytes. */ #define CAPTUREFILE_HEADER_SIZE 128 +/* Magic number size, for both 1.x and 2.x. */ +#define MAGIC_SIZE 4 + /* Magic number in Network Monitor 1.x files. */ -static const char netmon_1_x_magic[] = { - 'R', 'T', 'S', 'S' +static const char netmon_1_x_magic[MAGIC_SIZE] = { + "RTSS" }; /* Magic number in Network Monitor 2.x files. */ -static const char netmon_2_x_magic[] = { - 'G', 'M', 'B', 'U' +static const char netmon_2_x_magic[MAGIC_SIZE] = { + "GMBU" }; /* Network Monitor file header (minus magic number). */ @@ -193,7 +196,7 @@ static gboolean netmon_dump_close(wtap_dumper *wdh, int *err); int netmon_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; - char magic[sizeof netmon_1_x_magic]; + char magic[MAGIC_SIZE]; struct netmon_hdr hdr; int file_type; struct tm tm; @@ -209,16 +212,16 @@ int netmon_open(wtap *wth, int *err, gchar **err_info) /* Read in the string that should be at the start of a Network * Monitor file */ errno = WTAP_ERR_CANT_READ; - bytes_read = file_read(magic, sizeof magic, wth->fh); - if (bytes_read != sizeof magic) { + bytes_read = file_read(magic, MAGIC_SIZE, wth->fh); + if (bytes_read != MAGIC_SIZE) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } - if (memcmp(magic, netmon_1_x_magic, sizeof netmon_1_x_magic) != 0 - && memcmp(magic, netmon_2_x_magic, sizeof netmon_1_x_magic) != 0) { + if (memcmp(magic, netmon_1_x_magic, MAGIC_SIZE) != 0 && + memcmp(magic, netmon_2_x_magic, MAGIC_SIZE) != 0) { return 0; } @@ -227,9 +230,9 @@ int netmon_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } switch (hdr.ver_major) { diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index faa79a90f6..7d5bb10b54 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -595,6 +595,8 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info) { *err = file_error(wth->fh, err_info); g_free(nstrace_buf); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; return 0; } diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index a83d90f787..8609afa7fa 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -176,10 +176,7 @@ static gboolean netscreen_check_file_type(wtap *wth, int *err, gchar **err_info) } } else { /* EOF or error. */ - if (file_eof(wth->fh)) - *err = 0; - else - *err = file_error(wth->fh, err_info); + *err = file_error(wth->fh, err_info); return FALSE; } } @@ -193,10 +190,9 @@ int netscreen_open(wtap *wth, int *err, gchar **err_info) /* Look for a NetScreen snoop header line */ if (!netscreen_check_file_type(wth, err, err_info)) { - if (*err == 0) - return 0; - else + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; + return 0; } if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */ diff --git a/wiretap/nettl.c b/wiretap/nettl.c index e7c9dd1955..1fa4034f24 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -205,7 +205,7 @@ int nettl_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(file_hdr.magic, MAGIC_SIZE, wth->fh); if (bytes_read != MAGIC_SIZE) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -220,9 +220,9 @@ int nettl_open(wtap *wth, int *err, gchar **err_info) wth->fh); if (bytes_read != FILE_HDR_SIZE - MAGIC_SIZE) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* This is an nettl file */ diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 2096d95594..cd2ec51616 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -133,7 +133,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&file_header, sizeof file_header, wth->fh); if (bytes_read != sizeof file_header) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -184,7 +184,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&private_state->time_format, sizeof private_state->time_format, wth->fh); if (bytes_read != sizeof private_state->time_format) { *err = file_error(wth->fh, err_info); - if(*err == 0) + if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; } @@ -206,7 +206,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("Observer: bad record (offset to first packet %d < %d)", header_offset, offset); - return FALSE; + return -1; } seek_increment = header_offset - offset; if (seek_increment > 0) { @@ -218,9 +218,9 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&packet_header, sizeof packet_header, wth->fh); if (bytes_read != sizeof packet_header) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } PACKET_ENTRY_HEADER_FROM_LE_IN_PLACE(packet_header); diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 88043fc7b5..19bcc9b129 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -33,13 +33,16 @@ /* Capture file header, *including* magic number, is padded to 128 bytes. */ #define CAPTUREFILE_HEADER_SIZE 128 +/* Magic number size, in both 1.x and later files. */ +#define MAGIC_SIZE 4 + /* Magic number in NetXRay 1.x files. */ -static const char old_netxray_magic[] = { +static const char old_netxray_magic[MAGIC_SIZE] = { 'V', 'L', '\0', '\0' }; /* Magic number in NetXRay 2.0 and later, and Windows Sniffer, files. */ -static const char netxray_magic[] = { /* magic header */ +static const char netxray_magic[MAGIC_SIZE] = { 'X', 'C', 'P', '\0' }; @@ -339,7 +342,7 @@ static gboolean netxray_dump_close_2_0(wtap_dumper *wdh, int *err); int netxray_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; - char magic[sizeof netxray_magic]; + char magic[MAGIC_SIZE]; gboolean is_old; struct netxray_hdr hdr; guint network_type; @@ -378,17 +381,17 @@ int netxray_open(wtap *wth, int *err, gchar **err_info) /* Read in the string that should be at the start of a NetXRay * file */ errno = WTAP_ERR_CANT_READ; - bytes_read = file_read(magic, sizeof magic, wth->fh); - if (bytes_read != sizeof magic) { + bytes_read = file_read(magic, MAGIC_SIZE, wth->fh); + if (bytes_read != MAGIC_SIZE) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } - if (memcmp(magic, netxray_magic, sizeof magic) == 0) { + if (memcmp(magic, netxray_magic, MAGIC_SIZE) == 0) { is_old = FALSE; - } else if (memcmp(magic, old_netxray_magic, sizeof magic) == 0) { + } else if (memcmp(magic, old_netxray_magic, MAGIC_SIZE) == 0) { is_old = TRUE; } else { return 0; @@ -399,9 +402,9 @@ int netxray_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } if (is_old) { diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index cf92b54dff..b0145565b2 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -589,7 +589,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -606,16 +606,16 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(record_type, 2, wth->fh); if (bytes_read != 2) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } bytes_read = file_read(record_length, 4, wth->fh); if (bytes_read != 4) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } type = pletohs(record_type); @@ -630,9 +630,9 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&version, sizeof version, wth->fh); if (bytes_read != sizeof version) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* Check the data link type. */ @@ -654,7 +654,6 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) /* compressed or uncompressed Sniffer file? */ if (version.format != 1) { wth->file_type = WTAP_FILE_NGSNIFFER_COMPRESSED; - } else { wth->file_type = WTAP_FILE_NGSNIFFER_UNCOMPRESSED; } diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 07ba70eed9..a4aef3f717 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -61,11 +61,18 @@ int packetlogger_open(wtap *wth, int *err, gchar **err_info) packetlogger_header_t pl_hdr; guint8 type; - if(!packetlogger_read_header(&pl_hdr, wth->fh, err, err_info)) - return -1; + if(!packetlogger_read_header(&pl_hdr, wth->fh, err, err_info)) { + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } - if (file_read(&type, 1, wth->fh) <= 0) - return -1; + if (file_read(&type, 1, wth->fh) <= 0) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } /* Verify this file belongs to us */ if (!((8 <= pl_hdr.len) && (pl_hdr.len < 65536) && diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 179169bede..50842a1b5a 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -2053,7 +2053,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) if (bytes_read <= 0) { pcapng_debug0("pcapng_open: couldn't read first SHB"); *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index 028947af73..e8b890e020 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -155,6 +155,7 @@ int peekclassic_open(wtap *wth, int *err, gchar **err_info) { peekclassic_header_t ep_hdr; + int bytes_read; struct timeval reference_time; int file_encap; peekclassic_t *peekclassic; @@ -168,8 +169,14 @@ peekclassic_open(wtap *wth, int *err, gchar **err_info) * and we may have to add more checks at some point. */ g_assert(sizeof(ep_hdr.master) == PEEKCLASSIC_MASTER_HDR_SIZE); - wtap_file_read_unknown_bytes( - &ep_hdr.master, sizeof(ep_hdr.master), wth->fh, err, err_info); + bytes_read = file_read(&ep_hdr.master, (int)sizeof(ep_hdr.master), + wth->fh); + if (bytes_read != sizeof(ep_hdr.master)) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } /* * It appears that EtherHelp (a free application from WildPackets @@ -194,9 +201,14 @@ peekclassic_open(wtap *wth, int *err, gchar **err_info) /* get the secondary header */ g_assert(sizeof(ep_hdr.secondary.v567) == PEEKCLASSIC_V567_HDR_SIZE); - wtap_file_read_unknown_bytes( - &ep_hdr.secondary.v567, - sizeof(ep_hdr.secondary.v567), wth->fh, err, err_info); + bytes_read = file_read(&ep_hdr.secondary.v567, + (int)sizeof(ep_hdr.secondary.v567), wth->fh); + if (bytes_read != sizeof(ep_hdr.secondary.v567)) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } if ((0 != ep_hdr.secondary.v567.reserved[0]) || (0 != ep_hdr.secondary.v567.reserved[1]) || diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index ebc7eae53a..98a3cafacb 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -187,6 +187,7 @@ static int wtap_file_read_number (wtap *wth, guint32 *num, int *err, int peektagged_open(wtap *wth, int *err, gchar **err_info) { peektagged_section_header_t ap_hdr; + int bytes_read; int ret; guint32 fileVersion; guint32 mediaType; @@ -201,8 +202,13 @@ int peektagged_open(wtap *wth, int *err, gchar **err_info) #define NUM_PEEKTAGGED_ENCAPS (sizeof peektagged_encap / sizeof peektagged_encap[0]) peektagged_t *peektagged; - wtap_file_read_unknown_bytes(&ap_hdr, sizeof(ap_hdr), wth->fh, err, - err_info); + bytes_read = file_read(&ap_hdr, (int)sizeof(ap_hdr), wth->fh); + if (bytes_read != (int)sizeof(ap_hdr)) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } if (memcmp (ap_hdr.section_id, "\177ver", sizeof(ap_hdr.section_id)) != 0) return 0; /* doesn't begin with a "\177ver" section */ diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 0fc2e212c6..239f1a8e34 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -249,6 +249,7 @@ int pppdump_open(wtap *wth, int *err, gchar **err_info) { guint8 buffer[6]; /* Looking for: 0x07 t3 t2 t1 t0 ID */ + int bytes_read; pppdump_t *state; /* There is no file header, only packet records. Fortunately for us, @@ -259,8 +260,13 @@ pppdump_open(wtap *wth, int *err, gchar **err_info) * representing the timestamp. */ - wtap_file_read_unknown_bytes(buffer, sizeof(buffer), wth->fh, err, - err_info); + bytes_read = file_read(buffer, sizeof(buffer), wth->fh); + if (bytes_read != (int) sizeof(buffer)) { + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; + } if (buffer[0] == PPPD_RESET_TIME && (buffer[5] == PPPD_SENT_DATA || diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 0821498a2a..83d5f38a83 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -111,7 +111,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(r_magic, 8, wth->fh); if (bytes_read != 8) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -132,7 +132,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(t_magic, 11, wth->fh); if (bytes_read != 11) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -144,7 +144,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(t_magic, 11, wth->fh); if (bytes_read != 11) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -157,7 +157,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) wth->fh); if (bytes_read != sizeof(struct frame_date)) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } diff --git a/wiretap/snoop.c b/wiretap/snoop.c index c84d05158b..a89e98645e 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -264,7 +264,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -278,9 +278,9 @@ int snoop_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* @@ -339,14 +339,9 @@ int snoop_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&rec_hdr, sizeof rec_hdr, wth->fh); if (bytes_read != sizeof rec_hdr) { *err = file_error(wth->fh, err_info); - if (*err == 0 && bytes_read != 0) + if (*err == 0) *err = WTAP_ERR_SHORT_READ; - if (*err != 0) { - /* - * A real-live error. - */ - return -1; - } + return -1; /* * The file ends after the record header, which means this diff --git a/wiretap/tnef.c b/wiretap/tnef.c index 591a2f50dc..3afd1d49d6 100644 --- a/wiretap/tnef.c +++ b/wiretap/tnef.c @@ -109,7 +109,9 @@ int tnef_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - return (*err != 0) ? -1 : 0; + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } if (htolel(magic) != TNEF_SIGNATURE) diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index 3b79a07576..dea3d7c6d6 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -174,34 +174,29 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err, gchar **err_info) buf[TOSHIBA_LINE_LENGTH-1] = 0; for (line = 0; line < TOSHIBA_HEADER_LINES_TO_CHECK; line++) { - if (file_gets(buf, TOSHIBA_LINE_LENGTH, wth->fh) != NULL) { + if (file_gets(buf, TOSHIBA_LINE_LENGTH, wth->fh) == NULL) { + /* EOF or error. */ + *err = file_error(wth->fh, err_info); + return FALSE; + } - reclen = (guint) strlen(buf); - if (reclen < TOSHIBA_HDR_MAGIC_SIZE) { - continue; - } + reclen = (guint) strlen(buf); + if (reclen < TOSHIBA_HDR_MAGIC_SIZE) { + continue; + } - level = 0; - for (i = 0; i < reclen; i++) { - byte = buf[i]; - if (byte == toshiba_hdr_magic[level]) { - level++; - if (level >= TOSHIBA_HDR_MAGIC_SIZE) { - return TRUE; - } - } - else { - level = 0; + level = 0; + for (i = 0; i < reclen; i++) { + byte = buf[i]; + if (byte == toshiba_hdr_magic[level]) { + level++; + if (level >= TOSHIBA_HDR_MAGIC_SIZE) { + return TRUE; } } - } - else { - /* EOF or error. */ - if (file_eof(wth->fh)) - *err = 0; - else - *err = file_error(wth->fh, err_info); - return FALSE; + else { + level = 0; + } } } *err = 0; @@ -213,10 +208,9 @@ int toshiba_open(wtap *wth, int *err, gchar **err_info) { /* Look for Toshiba header */ if (!toshiba_check_file_type(wth, err, err_info)) { - if (*err == 0) - return 0; - else + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; + return 0; } wth->file_encap = WTAP_ENCAP_PER_PACKET; diff --git a/wiretap/visual.c b/wiretap/visual.c index 952894416d..1c35a35ad0 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -188,7 +188,7 @@ int visual_open(wtap *wth, int *err, gchar **err_info) if (bytes_read != sizeof magic) { *err = file_error(wth->fh, err_info); - if (*err != 0) + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } @@ -203,9 +203,9 @@ int visual_open(wtap *wth, int *err, gchar **err_info) if (bytes_read != sizeof vfile_hdr) { *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* Verify the file version is known */ diff --git a/wiretap/vms.c b/wiretap/vms.c index cbbc03fe13..a6f4899cbb 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -258,10 +258,9 @@ int vms_open(wtap *wth, int *err, gchar **err_info) { /* Look for VMS header */ if (!vms_check_file_type(wth, err, err_info)) { - if (*err == 0) - return 0; - else + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; + return 0; } wth->file_encap = WTAP_ENCAP_RAW_IP; diff --git a/wiretap/vwr.c b/wiretap/vwr.c index 573ff5f0bf..f932a5bbdf 100644 --- a/wiretap/vwr.c +++ b/wiretap/vwr.c @@ -899,9 +899,9 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) /* if we don't get it all, assume this isn't a vwr file */ if (file_read(rec, rec_size, wth->fh) != rec_size) { *err = file_error(wth->fh, err_info); - if (*err == 0) - return(UNKNOWN_FPGA); /* short read - not a vwr file */ - return(-1); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return(-1); + return(UNKNOWN_FPGA); /* short read - not a vwr file */ } @@ -983,9 +983,9 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) } *err = file_error(wth->fh, err_info); - if (*err == 0) - return(UNKNOWN_FPGA); /* short read - not a vwr file */ - return(-1); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return(-1); + return(UNKNOWN_FPGA); /* short read - not a vwr file */ } /* copy the actual packet data from the capture file into the target data block */ |