nstrace: Allow opening of files that are not multiples of 16kB

in size.

Wireshark/Tshark hangs when netscaler trace file smaller than 16KB is opened. 
It also hangs when a gzipped trace file is opened. With this fix, 
Files with sizes that are not multiple of 16KB and gzipped files can be opened.

Bug: 12083
Change-Id: I26b2fc406edafcb2f1f6161d69064ba5662ddf29
Reviewed-on: https://code.wireshark.org/review/13721
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
anilkumar911 2016-02-05 12:00:07 +05:30 committed by Michael Mann
parent 4d46047578
commit 875d95ea60
1 changed files with 14 additions and 5 deletions

View File

@ -1274,22 +1274,23 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
}\
nst_dataSize = nspr_getv20recordsize(hdp);\
rec_size = nst_dataSize - nstrace_tmpbuff_off;\
nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= NSPR_PAGESIZE_TRACE) ?\
nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= (guint)nstrace->nstrace_buflen) ?\
((nstrace_buf_offset + rec_size) - (NSPR_PAGESIZE_TRACE - 1)) : 0;\
while (nsg_nextPageOffset) {\
while (nstrace_buf_offset < NSPR_PAGESIZE_TRACE) {\
while (nstrace_buf_offset < nstrace->nstrace_buflen) {\
nstrace_tmpbuff[nstrace_tmpbuff_off++] = nstrace_buf[nstrace_buf_offset++];\
}\
nstrace_buflen = NSPR_PAGESIZE_TRACE;\
nstrace->xxx_offset += nstrace_buflen;\
nstrace_buflen = NSPR_PAGESIZE_TRACE;\
bytes_read = file_read(nstrace_buf, NSPR_PAGESIZE_TRACE, wth->fh);\
if ( !file_eof(wth->fh) && bytes_read != NSPR_PAGESIZE_TRACE) {\
return FALSE;\
} else {\
nstrace_buf_offset = 0;\
}\
nstrace_buflen = bytes_read;\
rec_size = nst_dataSize - nstrace_tmpbuff_off;\
nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= NSPR_PAGESIZE_TRACE) ?\
nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= (guint)nstrace->nstrace_buflen) ?\
((nstrace_buf_offset + rec_size) - (NSPR_PAGESIZE_TRACE- 1)): 0;\
} \
while (nstrace_tmpbuff_off < nst_dataSize) {\
@ -1297,7 +1298,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
}\
memcpy(ws_buffer_start_ptr(wth->frame_buffer), nstrace_tmpbuff, (phdr)->caplen);\
nstrace->nstrace_buf_offset = nstrace_buf_offset;\
nstrace->nstrace_buflen = nstrace_buflen = ((gint32)NSPR_PAGESIZE_TRACE);\
nstrace->nstrace_buflen = nstrace_buflen;\
nstrace->nsg_creltime = nsg_creltime;\
return TRUE;\
} while(0)
@ -1315,6 +1316,9 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *
int bytes_read = 0;
*err = 0;
*err_info = NULL;
if(nstrace_buflen == 0){
return FALSE; /* Reached End Of File */
}
do
{
@ -1328,6 +1332,11 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *
nstrace_buf[nstrace_buf_offset])
{
hdp = (nspr_hd_v20_t *) &nstrace_buf[nstrace_buf_offset];
if(nspr_getv20recordsize(hdp) == 0){
*err=WTAP_ERR_BAD_FILE;
*err_info = g_strdup("Zero size record found");
return FALSE;
}
switch (hdp->phd_RecordType)
{