commit 1921842b97fa1556ed595a55f861e65bfc2e8737
parent 309441792880e0fd0633b45348582ea191ca6788
Author: Chris Bracken <chris@bracken.jp>
Date: Fri, 6 Mar 2026 17:39:45 +0900
fs_inmemory: check fread return value
Make sure that the number of bytes read from the disk file matches the
expected file size. Prevents the fake filesystem from silently using
incomplete content.
Diffstat:
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/fs_inmemory.c b/src/fs_inmemory.c
@@ -1,5 +1,6 @@
#include "fs_inmemory.h"
+#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -138,7 +139,9 @@ static int inmemory_rename(const char* oldpath, const char* newpath) {
fseek(f, 0, SEEK_SET);
char* content = malloc(fsize + 1);
- fread(content, 1, fsize, f);
+ if (fread(content, 1, fsize, f) != (size_t)fsize) {
+ err(1, "fread: %s", oldpath);
+ }
content[fsize] = '\0';
fclose(f);