summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-04 17:28:04 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:49 +0100
commiteba541dae4461603e16efc12019c38e87eb4fcb1 (patch)
tree1231c0720df005b791824da9efc6c052962cd0a5 /signal-composer-binding/signal-composer.cpp
parent55e4e3b31f2cbec776eb89c0b780f895fa0f0b86 (diff)
Avoid mem leack, overwriting, initializing variable.
Fix a memory squashing bug that segfault binder when loading directory searching for binding. Change-Id: Iedc6747d8ce49e7ff5fc2013bb7d03b5b553b89c Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer.cpp')
-rw-r--r--signal-composer-binding/signal-composer.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 572a6c4..d9d004c 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -177,6 +177,7 @@ CtlActionT* Composer::convert2Action(const std::string& name, json_object* actio
char *function;
const char *plugin;
CtlActionT *ctlAction = new CtlActionT;
+ memset(ctlAction, 0, sizeof(CtlActionT));
if(actionJ &&
!wrap_json_unpack(actionJ, "{ss,s?s,s?o !}", "function", &function,
@@ -218,9 +219,12 @@ CtlActionT* Composer::convert2Action(const std::string& name, json_object* actio
}
if(ctlActionJ)
- {ActionLoadOne(nullptr, ctlAction, ctlActionJ, 0);}
+ {
+ if(!ActionLoadOne(nullptr, ctlAction, ctlActionJ, 0))
+ return ctlAction;
+ }
- return ctlAction;
+ return nullptr;
}
/// @brief Add the builtin plugin in the default plugins section definition
@@ -359,13 +363,13 @@ int Composer::loadOneSignal(json_object* signalJ)
const char *id = nullptr,
*event = nullptr,
*unit = nullptr;
- int retention;
+ int retention = 0;
double frequency=0.0;
std::vector<std::string> dependsV;
ssize_t sep;
std::shared_ptr<SourceAPI> src = nullptr;
- int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?F,s?s,s?F,s?o !}",
+ int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?i,s?s,s?F,s?o !}",
"uid", &id,
"event", &event,
"depends", &dependsJ,
@@ -443,8 +447,9 @@ int Composer::loadOneSignal(json_object* signalJ)
unit = !unit ? "" : unit;
// Set default onReceived action if not specified
- char* uid = strndup("onReceived_", 11);
- uid = strncat(uid, id, strlen(id));
+ char uid[CONTROL_MAXPATH_LEN] = "onReceived_";
+ strncat(uid, id, strlen(id));
+
if(!onReceivedJ)
{
onReceivedCtl = src->signalsDefault().onReceived ?