From 93840f7fa2f23d10e0b5fef1562e47f16591a2fd Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 9 Jan 2020 23:13:47 -0800 Subject: binding: hvac: improve onEvent handler * remove memory leak of json_object * remove security risk of displaying event message in journal Bug-AGL: SPEC-2984 Change-Id: I6287093a79d382a895a61d83263f3f4208ed999b Signed-off-by: Matt Ranostay --- binding/hvac-demo-binding.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/binding/hvac-demo-binding.c b/binding/hvac-demo-binding.c index 1d5e6ac..da007ec 100644 --- a/binding/hvac-demo-binding.c +++ b/binding/hvac-demo-binding.c @@ -717,20 +717,18 @@ static int bindingServiceInit(afb_api_t api) static void onEvent(afb_api_t api, const char *event_name, struct json_object *object) { - json_object *language = json_object_new_object(); json_object *id_evt_name, *current_identity; - AFB_API_NOTICE(api, "Event '%s' received: %s", event_name, - json_object_to_json_string_ext(object, JSON_C_TO_STRING_PRETTY)); - if (json_object_object_get_ex(object, "eventName", &id_evt_name) && !strcmp(json_object_get_string(id_evt_name), "login") && !afb_api_call_sync(api, "identity", "get", json_object_new_object(), ¤t_identity, NULL, NULL)) { + json_object *language = NULL; json_object *response; if (! json_object_object_get_ex(current_identity, "response", &response) || ! json_object_object_get_ex(response, "graphPreferredLanguage", &language)) { language = json_object_new_string("en_US"); } afb_event_broadcast(event, language); + return; } } -- cgit 1.2.3-korg