Subject: [PATCH] fix: check parameters in json-write.c

From: "mark via GitGitGadget" <[email-masked]>
Date: Tue, 19 Sep 2023 11:54:58 +0000

From: wangsirun <[email-masked]>

When I used the json-writer.c file as a lib, I found that
it often caused coredump errors, so I submitted this patch

Signed-off-by: sirun Wang <[email-masked]>
---
    fix: check parameters in json-write.c
    
    When I used the json-writer.c file as a lib, I found that it often
    caused coredump errors, so I submitted this patch

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1576%2Fwangsirun%2Fjson-write-fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1576/wangsirun/json-write-fix-v1
Pull-Request: https://github.com/git/git/pull/1576

 json-writer.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/json-writer.c b/json-writer.c
index 005c820aa42..23ba7046e5d 100644
--- a/json-writer.c
+++ b/json-writer.c
@@ -20,6 +20,11 @@ static void append_quoted_string(struct strbuf *out, const char *in)
 {
 	unsigned char c;
 
+	if (!in || !*in) {
+		strbuf_addstr(out, "\"\"");
+		return;
+	}
+
 	strbuf_addch(out, '"');
 	while ((c = *in++) != '\0') {
 		if (c == '"')

base-commit: d4a83d07b8cc66d4afac2f33a8af729f2ba93bba
-- 
gitgitgadget