summaryrefslogtreecommitdiff
path: root/wiretap/json.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-11-07 14:46:18 -0800
committerGuy Harris <guy@alum.mit.edu>2015-11-07 22:46:47 +0000
commita8766cc9f9fcc531f4a04080377ac0e8624d488c (patch)
tree625502f77f15ec5ed2035a01372c093b54f6ec8c /wiretap/json.c
parent4897ef173aae7e38221937258d2c506a198c2c17 (diff)
downloadwireshark-a8766cc9f9fcc531f4a04080377ac0e8624d488c.tar.gz
Check for read errors in the open routine.
While we're at it, rename a variable to avoid colliding with the read() routine. Change-Id: I6629ec761f48751f34a2e7d04180d7583ad85710 Reviewed-on: https://code.wireshark.org/review/11626 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/json.c')
-rw-r--r--wiretap/json.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/wiretap/json.c b/wiretap/json.c
index 9e81f2e56d..e7cf2d68a8 100644
--- a/wiretap/json.c
+++ b/wiretap/json.c
@@ -92,18 +92,29 @@ static gboolean json_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of
return json_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
}
-wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info _U_)
+wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info)
{
guint8* filebuf;
- guint read;
+ int bytes_read;
filebuf = (guint8*)g_malloc0(MAX_FILE_SIZE);
if (!filebuf)
return WTAP_OPEN_ERROR;
- read = file_read(filebuf, MAX_FILE_SIZE, wth->fh);
+ bytes_read = file_read(filebuf, MAX_FILE_SIZE, wth->fh);
+ if (bytes_read < 0) {
+ /* Read error. */
+ *err = file_error(wth->fh, err_info);
+ g_free(filebuf);
+ return WTAP_OPEN_ERROR;
+ }
+ if (bytes_read == 0) {
+ /* empty file, not *anybody's* */
+ g_free(filebuf);
+ return WTAP_OPEN_NOT_MINE;
+ }
- if (jsmn_is_json(filebuf, read) == FALSE) {
+ if (jsmn_is_json(filebuf, bytes_read) == FALSE) {
g_free(filebuf);
return WTAP_OPEN_NOT_MINE;
}