mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-17 17:52:43 +03:00
deal with ftell errors and short reads (coverity 1230589 1230588)
This commit is contained in:
parent
ee3247f532
commit
20f99a8e96
@ -460,6 +460,7 @@ window_init_fname(const char *title,
|
|||||||
nserror ret;
|
nserror ret;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *ndata;
|
char *ndata;
|
||||||
|
long tell_len;
|
||||||
size_t ndata_len;
|
size_t ndata_len;
|
||||||
|
|
||||||
f = fopen(filename, "r");
|
f = fopen(filename, "r");
|
||||||
@ -471,17 +472,21 @@ window_init_fname(const char *title,
|
|||||||
return NSERROR_BAD_SIZE;
|
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) {
|
if (fseek(f, 0, SEEK_SET) != 0) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return NSERROR_BAD_SIZE;
|
return NSERROR_BAD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndata = malloc(ndata_len);
|
ndata = malloc(tell_len);
|
||||||
|
|
||||||
fread(ndata, 1, ndata_len, f);
|
|
||||||
|
|
||||||
|
ndata_len = fread(ndata, 1, tell_len, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
ret = window_init(title, leafname, ndata, ndata_len);
|
ret = window_init(title, leafname, ndata, ndata_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user