From eae5c6aa52d50a2160e1b1b271254122880818e8 Mon Sep 17 00:00:00 2001 From: hanjinpeng Date: Mon, 14 Sep 2026 13:02:03 -0400 Subject: [PATCH] util: do not parse truncated input on append failure fjson_object_from_fd() ignored the return value of printbuf_memappend(). If an append failed (e.g. out of memory) it went on to parse whatever had been accumulated so far, silently returning an object built from truncated input. Check the result and fail instead. --- json_util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/json_util.c b/json_util.c index acdc8c2..46274bf 100644 --- a/json_util.c +++ b/json_util.c @@ -71,7 +71,12 @@ struct fjson_object* fjson_object_from_fd(int fd) return NULL; } while((ret = read(fd, buf, FJSON_FILE_BUF_SIZE)) > 0) { - printbuf_memappend(pb, buf, ret); + if(printbuf_memappend(pb, buf, ret) < 0) { + /* do not silently parse truncated input on OOM */ + MC_ERROR("fjson_object_from_fd: printbuf_memappend failed\n"); + printbuf_free(pb); + return NULL; + } } if(ret < 0) { MC_ERROR("fjson_object_from_fd: error reading fd %d: %s\n", fd, strerror(errno));