diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index 9a2465ad3..4e117585b 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -315,14 +315,21 @@ char * os_readfile(const char *name, size_t *len) { FILE *f; char *buf; + long pos; f = fopen(name, "rb"); if (f == NULL) return NULL; - fseek(f, 0, SEEK_END); - *len = ftell(f); - fseek(f, 0, SEEK_SET); + if (fseek(f, 0, SEEK_END) < 0 || (pos = ftell(f)) < 0) { + fclose(f); + return NULL; + } + *len = pos; + if (fseek(f, 0, SEEK_SET) < 0) { + fclose(f); + return NULL; + } buf = os_malloc(*len); if (buf == NULL) {