diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-11-07 14:46:18 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-11-07 22:46:47 +0000 |
commit | a8766cc9f9fcc531f4a04080377ac0e8624d488c (patch) | |
tree | 625502f77f15ec5ed2035a01372c093b54f6ec8c /wiretap/json.c | |
parent | 4897ef173aae7e38221937258d2c506a198c2c17 (diff) |
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.c | 19 |
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; } |