From af2c74d6c06a9fb08f7de15d41162d09f871a62e Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 19 Jul 2018 09:46:57 +0200 Subject: json: Don't use strdup but the xtrystrdup wrapper. * src/gpgme-json.c (create_keylist_patterns): Use CNT as first arg for xcalloc. (process_request): s/strdup/xtrystrdup/. -- calloc takes two arguments so to be able to detect integer overflow. Thus if we switch from malloc to calloc we should utilize that. Signed-off-by: Werner Koch --- src/gpgme-json.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/gpgme-json.c') diff --git a/src/gpgme-json.c b/src/gpgme-json.c index cc3abfe5..81b70aad 100644 --- a/src/gpgme-json.c +++ b/src/gpgme-json.c @@ -701,7 +701,7 @@ create_keylist_patterns (cjson_t request, const char *name) if (*p == '\n') cnt++; - ret = xcalloc (1, cnt * sizeof *ret); + ret = xcalloc (cnt, sizeof *ret); for (p = keystring, tmp = keystring; *p; p++) { @@ -3214,8 +3214,11 @@ process_request (const char *request) res = encode_and_chunk (json, response); if (!res) { - log_error ("Printing JSON data failed\n"); - cjson_t err_obj = error_object (NULL, "Printing JSON data failed"); + cjson_t err_obj; + + log_error ("printing JSON data failed\n"); + + err_obj = error_object (NULL, "Printing JSON data failed"); if (opt_interactive) res = cJSON_Print (err_obj); res = cJSON_PrintUnformatted (err_obj); @@ -3228,7 +3231,7 @@ process_request (const char *request) if (!res) { /* Can't happen unless we created a broken error_object above */ - return strdup ("Bug: Fatal error in process request\n"); + return xtrystrdup ("Bug: Fatal error in process request\n"); } return res; } @@ -3626,7 +3629,7 @@ native_messaging_repl (void) } else /* Process request */ { - request[n] = '\0'; /* Esnure that request has an end */ + request[n] = '\0'; /* Ensure that request has an end */ if (opt_debug) log_debug ("request='%s'\n", request); xfree (response); -- cgit v1.2.3