From 586c620609ebb485bc123bdd1da0a890cf4f5490 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Feb 2015 17:54:13 -0500 Subject: [PATCH] Also treat file reading as an error if `ftell` reports invalid length. `ftell` is documented to return -1L if the function failed to get the current position indicator in the stream. The possibility is easily set aside just by checking if the function returned a negative length. --- file_ops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/file_ops.c b/file_ops.c index e477f3d044..55d2a18cdc 100644 --- a/file_ops.c +++ b/file_ops.c @@ -110,6 +110,8 @@ static bool read_generic_file(const char *path, void **buf, ssize_t *len) fseek(file, 0, SEEK_END); _len = ftell(file); + if (_len < 0) + goto error; rewind(file);