commit c28430201687c4c4e4dc0ddb049ae72d47acb741
parent 4bc1c3617eaf670fc84d41e1e14c2edc2cf43d3c
Author: Chris Bracken <chris@bracken.jp>
Date: Wed, 20 May 2026 22:20:11 +0900
tests: fix potential bad reads
If ftell returns a negative value or malloc fails, bail out early.
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/fs_inmemory.c b/src/fs_inmemory.c
@@ -137,9 +137,15 @@ static int inmemory_rename(const char* oldpath, const char* newpath) {
if (f) {
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
+ if (fsize < 0) {
+ err(1, "ftell: %s", oldpath);
+ }
fseek(f, 0, SEEK_SET);
char* content = malloc(fsize + 1);
+ if (!content) {
+ err(1, "malloc");
+ }
if (fread(content, 1, fsize, f) != (size_t)fsize) {
err(1, "fread: %s", oldpath);
}