From be632059b48b5c6b5d767c8b37afe0582c23cd38 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Oct 20 2020 18:47:52 +0000 Subject: Save a copy of the IPA error message when parsing the JSON result json_decref() is freeing the parsed value so the error message was undefined. Issued discovered in https://pagure.io/freeipa/issue/8537 --- diff --git a/src/ipa.c b/src/ipa.c index 8c089e6..361cec9 100644 --- a/src/ipa.c +++ b/src/ipa.c @@ -597,6 +597,7 @@ parse_json_result(const char *result, char **error_message) { json_t *j_error_obj = NULL; int error_code = 0; + char * message = NULL; j_root = json_loads(result, 0, &j_error); if (!j_root) { @@ -612,13 +613,14 @@ parse_json_result(const char *result, char **error_message) { if (json_unpack_ex(j_error_obj, &j_error, 0, "{s:i, s:s}", "code", &error_code, - "message", error_message) != 0) { + "message", &message) != 0) { cm_log(0, "Failed extracting error from JSON-RPC response: %s\n", j_error.text); json_decref(j_root); return -1; } - cm_log(0, "JSON-RPC error: %d: %s\n", error_code, *error_message); + cm_log(0, "JSON-RPC error: %d: %s\n", error_code, message); + *error_message = strdup(message); json_decref(j_root); return error_code; } @@ -814,6 +816,7 @@ submit: } cleanup: + free(error_message); json_decref(j_root); cm_submit_h_cleanup(hctx); talloc_free(ctx);