From 0a4e212e4b647dba6d26a47acf4775a972220b26 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 10 May 2011 21:53:10 +0000 Subject: [PATCH] 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 --- wiretap/nettl.c | 59 ++++++++++++++++++++++++++++++------------------- 1 file 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);