diff options
author | Vincent Sanders <vince@kyllikki.org> | 2014-08-18 17:28:06 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2014-08-18 17:28:06 +0100 |
commit | 20f99a8e961036c2ac8754f8352423a90159e0d0 (patch) | |
tree | 9546f52bb1b9cfbf0cd2986553eb95178c7b856b | |
parent | ee3247f532a605e09fea3461344536730e77ee04 (diff) | |
download | netsurf-20f99a8e961036c2ac8754f8352423a90159e0d0.tar.gz |
deal with ftell errors and short reads (coverity 1230589 1230588)
-rw-r--r-- | gtk/viewdata.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/gtk/viewdata.c b/gtk/viewdata.c index fc7537d80..1b5bfb153 100644 --- a/gtk/viewdata.c +++ b/gtk/viewdata.c @@ -460,6 +460,7 @@ window_init_fname(const char *title, nserror ret; FILE *f; char *ndata; + long tell_len; size_t ndata_len; f = fopen(filename, "r"); @@ -471,17 +472,21 @@ window_init_fname(const char *title, return NSERROR_BAD_SIZE; } - ndata_len = ftell(f); + tell_len = ftell(f); + if (tell_len == -1) { + fclose(f); + return NSERROR_BAD_SIZE; + } if (fseek(f, 0, SEEK_SET) != 0) { fclose(f); return NSERROR_BAD_SIZE; } - ndata = malloc(ndata_len); - - fread(ndata, 1, ndata_len, f); + ndata = malloc(tell_len); + ndata_len = fread(ndata, 1, tell_len, f); + fclose(f); ret = window_init(title, leafname, ndata, ndata_len); |