diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index aa3a51494f..ce6fd45676 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -531,7 +531,7 @@ static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err); static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err); static int SnifferDecompress( unsigned char * inbuf, size_t inlen, - unsigned char * outbuf, size_t outlen, int *err ); + unsigned char * outbuf, size_t outlen, int *err, gchar **err_info ); static gint64 ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random, int *err, gchar **err_info); static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, @@ -2179,6 +2179,8 @@ ngsniffer_dump_close(wtap_dumper *wdh, int *err) outbuf - decompressed contents, could contain a partial Sniffer record at the end. outlen - length of outbuf. + err - return error code here + err_info - for WTAP_ERR_BAD_FILE, return descriptive string here Return value is the number of bytes in outbuf on return. */ @@ -2190,7 +2192,8 @@ ngsniffer_dump_close(wtap_dumper *wdh, int *err) #define CHECK_INPUT_POINTER( length ) \ if ( pin + (length - 1) >= pin_end ) \ { \ - *err = WTAP_ERR_UNC_TRUNCATED; \ + *err = WTAP_ERR_BAD_FILE; \ + *err_info = g_strdup("ngsniffer: Compressed data item goes past the end of the compressed block"); \ return ( -1 ); \ } @@ -2240,13 +2243,15 @@ ngsniffer_dump_close(wtap_dumper *wdh, int *err) /* Check if offset would put us back past begin of buffer */ \ if ( pout - offset < outbuf ) \ { \ - *err = WTAP_ERR_UNC_BAD_OFFSET; \ + *err = WTAP_ERR_BAD_FILE; \ + *err_info = g_strdup("ngsniffer: LZ77 compressed data has bad offset to string"); \ return ( -1 ); \ } \ /* Check if offset would cause us to copy on top of ourselves */ \ if ( pout - offset + length > pout ) \ { \ - *err = WTAP_ERR_UNC_BAD_OFFSET; \ + *err = WTAP_ERR_BAD_FILE; \ + *err_info = g_strdup("ngsniffer: LZ77 compressed data has bad offset to string"); \ return ( -1 ); \ } \ /* Copy the string from previous text to output position, \ @@ -2256,7 +2261,7 @@ ngsniffer_dump_close(wtap_dumper *wdh, int *err) static int SnifferDecompress(unsigned char *inbuf, size_t inlen, unsigned char *outbuf, - size_t outlen, int *err) + size_t outlen, int *err, gchar **err_info) { unsigned char * pin = inbuf; unsigned char * pout = outbuf; @@ -2383,7 +2388,7 @@ SnifferDecompress(unsigned char *inbuf, size_t inlen, unsigned char *outbuf, } /* - * XXX - is there any guarantee that this is big enough to hold the + * XXX - is there any guarantee that 65535 bytes is big enough to hold the * uncompressed data from any blob? */ #define OUTBUF_SIZE 65536 @@ -2562,7 +2567,8 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, } else { /* Decompress the blob */ out_len = SnifferDecompress(file_inbuf, in_len, - comp_stream->buf, OUTBUF_SIZE, err); + comp_stream->buf, OUTBUF_SIZE, err, + err_info); if (out_len < 0) { g_free(file_inbuf); return -1; diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 30ed6a2420..88b587e12a 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -855,15 +855,9 @@ static const char *wtap_errlist[] = { /* WTAP_ERR_SHORT_WRITE */ "Less data was written than was requested", - /* WTAP_ERR_UNC_TRUNCATED */ - "Uncompression error: data oddly truncated", - /* WTAP_ERR_UNC_OVERFLOW */ "Uncompression error: data would overflow buffer", - /* WTAP_ERR_UNC_BAD_OFFSET */ - "Uncompression error: bad LZ77 offset", - /* WTAP_ERR_RANDOM_OPEN_STDIN */ "The standard input cannot be opened for random access", diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 3dd525826b..7d01c15290 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1651,42 +1651,36 @@ int wtap_register_encap_type(const char* name, const char* short_name); #define WTAP_ERR_SHORT_WRITE -14 /** An attempt to write wrote less data than it should have */ -#define WTAP_ERR_UNC_TRUNCATED -15 - /** Sniffer compressed data was oddly truncated */ - -#define WTAP_ERR_UNC_OVERFLOW -16 +#define WTAP_ERR_UNC_OVERFLOW -15 /** Uncompressing Sniffer data would overflow buffer */ -#define WTAP_ERR_UNC_BAD_OFFSET -17 - /** LZ77 compressed data has bad offset to string */ - -#define WTAP_ERR_RANDOM_OPEN_STDIN -18 +#define WTAP_ERR_RANDOM_OPEN_STDIN -16 /** We're trying to open the standard input for random access */ -#define WTAP_ERR_COMPRESSION_NOT_SUPPORTED -19 +#define WTAP_ERR_COMPRESSION_NOT_SUPPORTED -17 /* The filetype doesn't support output compression */ -#define WTAP_ERR_CANT_SEEK -20 +#define WTAP_ERR_CANT_SEEK -18 /** An attempt to seek failed, reason unknown */ -#define WTAP_ERR_CANT_SEEK_COMPRESSED -21 +#define WTAP_ERR_CANT_SEEK_COMPRESSED -19 /** An attempt to seek on a compressed stream */ -#define WTAP_ERR_DECOMPRESS -22 +#define WTAP_ERR_DECOMPRESS -20 /** Error decompressing */ -#define WTAP_ERR_INTERNAL -23 +#define WTAP_ERR_INTERNAL -21 /** "Shouldn't happen" internal errors */ -#define WTAP_ERR_PACKET_TOO_LARGE -24 +#define WTAP_ERR_PACKET_TOO_LARGE -22 /** Packet being written is larger than we support; do not use when reading, use WTAP_ERR_BAD_FILE instead */ -#define WTAP_ERR_CHECK_WSLUA -25 +#define WTAP_ERR_CHECK_WSLUA -23 /** Not really an error: the file type being checked is from a Lua plugin, so that the code will call wslua_can_write_encap() instead if it gets this */ -#define WTAP_ERR_REC_TYPE_UNSUPPORTED -26 +#define WTAP_ERR_REC_TYPE_UNSUPPORTED -24 /** Specified record type can't be written to that file type */ #ifdef __cplusplus