summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2019-01-15 14:20:14 +0100
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-01-16 13:19:31 +0000
commitf8531f98503e72238253d4faff634293ad4d1941 (patch)
tree0ea2b270211791dfbf36900e45463e62db047701
parentf1c3b6be4e006b97940c480ee416eb461ec36e2c (diff)
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 <thierry.bultel@iot.bzh>
-rw-r--r--ctl-lib/ctl-action.c11
1 files changed, 7 insertions, 4 deletions
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++;