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));