summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2020-01-09 23:13:47 -0800
committerMatt Ranostay <matt.ranostay@konsulko.com>2020-01-09 23:33:26 -0800
commit93840f7fa2f23d10e0b5fef1562e47f16591a2fd (patch)
tree539b705300bdf2276ecf7c7292fe33380b9eb044
parent8554afd321db96bdf0c82e9df0bdf934c7692c39 (diff)
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 <matt.ranostay@konsulko.com>
-rw-r--r--binding/hvac-demo-binding.c6
1 files 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(), &current_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;
}
}