From 0abcbce3bbae7e1068caacedbccc1563ff005df4 Mon Sep 17 00:00:00 2001 From: Sanjay Kumar Date: Sat, 5 Aug 2017 23:52:49 +0530 Subject: [PATCH] json_dump_file API returns success even when fclose fails (consider disk full case). API should check the return value of fclose before returning success to its caller. fwrite may not write anything into the file, it simply returns the number of bytes written into the buffer. When disk is full and fclose is called, it results in truncation of the file (resulting in zero sized file). Since, API is returning success, its caller can't take any remedial action on its failure. --- src/dump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dump.c b/src/dump.c index a23fabb..63a9c15 100644 --- a/src/dump.c +++ b/src/dump.c @@ -481,7 +481,9 @@ int json_dump_file(const json_t *json, const char *path, size_t flags) result = json_dumpf(json, output, flags); - fclose(output); + if(fclose(output) != 0) + return -1; + return result; }