From 17fce1cf7818a529abdd0325af0125f21d4c6e4e Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 11 Nov 2023 13:28:32 +1100 Subject: [PATCH] [client] util: fix failure to check result of `ftell` for error --- client/src/util.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/util.c b/client/src/util.c index 84780582..bad2b1dd 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -48,7 +48,6 @@ bool util_fileGetContents(const char * filename, char ** buffer, size_t * length return false; } - long fsize = ftell(fh); if (fseek(fh, 0, SEEK_SET) != 0) { DEBUG_ERROR("Failed to seek"); @@ -56,6 +55,14 @@ bool util_fileGetContents(const char * filename, char ** buffer, size_t * length return false; } + long fsize = ftell(fh); + if (fsize < 0) + { + DEBUG_ERROR("Failed to get the size"); + fclose(fh); + return false; + } + *buffer = malloc(fsize + 1); if (!*buffer) {