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.
This commit is contained in:
Andre Heinecke 2018-07-16 19:47:11 +02:00
parent cc21101a74
commit 1686e07e77
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -3104,7 +3104,7 @@ process_request (const char *request)
int helpmode; int helpmode;
int is_getmore = 0; int is_getmore = 0;
const char *op; const char *op;
char *res; char *res = NULL;
int idx; int idx;
response = xjson_CreateObject (); response = xjson_CreateObject ();
@ -3188,7 +3188,7 @@ process_request (const char *request)
else else
res = cJSON_PrintUnformatted (response); res = cJSON_PrintUnformatted (response);
} }
else else if (json)
res = encode_and_chunk (json, response); res = encode_and_chunk (json, response);
if (!res) if (!res)
log_error ("Printing JSON data failed\n"); log_error ("Printing JSON data failed\n");