From 8af5764a9c40c03c90fb8440e006b4bc8b6b7628 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 26 Feb 2021 10:11:28 +0100 Subject: [PATCH] json: fix oom when adding a long string --- common/json_stream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/json_stream.c b/common/json_stream.c index 45ac30ebd330..20af11a29aec 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -194,8 +194,9 @@ void json_add_jsonstr(struct json_stream *js, size_t len = strlen(jsonstr); p = json_member_direct(js, fieldname, len); - - memcpy(p, jsonstr, len); + /* Could be OOM! */ + if (p) + memcpy(p, jsonstr, len); } /* This is where we read the json_stream and write it to conn */