From 1686e07e77a1eee3b2708d0231a5a549956021f7 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 16 Jul 2018 19:47:11 +0200 Subject: [PATCH] json: Fix crash on invalid json * src/gpgme-json.c (process_request): Init res. Check for json object before encode and chunk. -- If json is invalid we can't read chunksize and would crash in encode and chunk. --- src/gpgme-json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gpgme-json.c b/src/gpgme-json.c index 0aeb7f91..06f09ef0 100644 --- a/src/gpgme-json.c +++ b/src/gpgme-json.c @@ -3104,7 +3104,7 @@ process_request (const char *request) int helpmode; int is_getmore = 0; const char *op; - char *res; + char *res = NULL; int idx; response = xjson_CreateObject (); @@ -3188,7 +3188,7 @@ process_request (const char *request) else res = cJSON_PrintUnformatted (response); } - else + else if (json) res = encode_and_chunk (json, response); if (!res) log_error ("Printing JSON data failed\n");