summaryrefslogtreecommitdiff
path: root/wiretap/nettl.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2011-05-10 21:53:10 +0000
committerGuy Harris <guy@alum.mit.edu>2011-05-10 21:53:10 +0000
commit0a4e212e4b647dba6d26a47acf4775a972220b26 (patch)
treed858074648d9472200d9f326518bf3d69225b213 /wiretap/nettl.c
parent2ca5312b6476d37ad709ca5eb688952004371fd5 (diff)
downloadwireshark-0a4e212e4b647dba6d26a47acf4775a972220b26.tar.gz
file_read() can return -1; don't just blindly add it to a previous
file_read() return value. Use wtap_file_read_expected_bytes() in a number of places. svn path=/trunk/; revision=37054
Diffstat (limited to 'wiretap/nettl.c')
-rw-r--r--wiretap/nettl.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/wiretap/nettl.c b/wiretap/nettl.c
index bd117e8286..e719e7aad7 100644
--- a/wiretap/nettl.c
+++ b/wiretap/nettl.c
@@ -653,32 +653,45 @@ static gboolean
nettl_read_rec_data(FILE_T fh, guchar *pd, int length, int *err,
gchar **err_info, gboolean fddihack)
{
- int bytes_read;
- guchar *p=NULL;
+ int bytes_to_read, bytes_read;
guint8 dummy[3];
- if (fddihack == TRUE) {
- /* read in FC, dest, src, DSAP and SSAP */
- if (file_read(pd, 15, fh) == 15) {
- if (pd[13] == 0xAA) {
- /* it's SNAP, have to eat 3 bytes??? */
- if (file_read(dummy, 3, fh) == 3) {
- p=pd+15;
- bytes_read = file_read(p, length-18, fh);
- bytes_read += 18;
- } else {
- bytes_read = -1;
- }
- } else {
- /* not SNAP */
- p=pd+15;
- bytes_read = file_read(p, length-15, fh);
- bytes_read += 15;
- }
- } else
- bytes_read = -1;
+ if (fddihack) {
+ /* read in FC, dest, src, DSAP and SSAP */
+ bytes_to_read = 15;
+ if (bytes_to_read > length)
+ bytes_to_read = length;
+ bytes_read = file_read(pd, bytes_to_read, fh);
+ if (bytes_read != bytes_to_read) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return FALSE;
+ }
+ length -= bytes_read;
+ if (length == 0) {
+ /* There's nothing past the FC, dest, src, DSAP and SSAP */
+ return TRUE;
+ }
+ if (pd[13] == 0xAA) {
+ /* it's SNAP, have to eat 3 bytes??? */
+ bytes_to_read = 3;
+ if (bytes_to_read > length)
+ bytes_to_read = length;
+ bytes_read = file_read(dummy, bytes_to_read, fh);
+ if (bytes_read != bytes_to_read) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return FALSE;
+ }
+ length -= bytes_read;
+ if (length == 0) {
+ /* There's nothing past the FC, dest, src, DSAP, SSAP, and 3 bytes to eat */
+ return TRUE;
+ }
+ }
+ bytes_read = file_read(pd + 15, length, fh);
} else
- bytes_read = file_read(pd, length, fh);
+ bytes_read = file_read(pd, length, fh);
if (bytes_read != length) {
*err = file_error(fh, err_info);