From f8531f98503e72238253d4faff634293ad4d1941 Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Tue, 15 Jan 2019 14:20:14 +0100 Subject: ctl-action: fixed the calculation of the number of actions When adding actions to a section, the number of existing actions was badly calculated, leading to access to uninitialized memory when walking through the list later, because there was a missing null action at the end. Change-Id: I18390463cbe94d1c8788add33f99814404c59760 Signed-off-by: Thierry Bultel --- ctl-lib/ctl-action.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ctl-lib/ctl-action.c') diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 0bd9c7b..2b0813b 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -373,13 +373,16 @@ int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *a CtlActionT *savedActions = section->actions; CtlActionT *newActions = ActionConfig(apiHandle, actionsJ, exportApi); - while(savedActions[actionsNb].uid) + while(savedActions[idx++].uid) { actionsNb++; - while(newActions[actionsNb].uid) + } + idx = 0; + while(newActions[idx++].uid) { actionsNb++; - + } + /* Allocate one more, NULL uid marks the end of the table */ actions = calloc(actionsNb + 1, sizeof(CtlActionT)); - + idx = 0; while(savedActions[idx].uid) { actions[idx] = savedActions[idx]; idx++; -- cgit 1.2.3-korg