aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-config.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-11-03 15:42:26 +0100
committerRonan Le Martret <ronan.lemartret@iot.bzh>2017-11-24 10:38:06 +0100
commitaf19faae21bf209515dcb220a102b4adf7f5b7d5 (patch)
tree735dfc4b2dc21af14cf2f948ef8dfe37888dd899 /ctl-lib/ctl-config.c
parent19fd8c1f4b4d54d5dc2c4f586baed04e220142b1 (diff)
Fix: strncpy does't add null char at the end
Fix: handle null response from CtlScanConfig() Change-Id: Icbe2a649886998078adda35b0d0dfd1c46e8fe31 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-config.c')
-rw-r--r--ctl-lib/ctl-config.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index c315f9c..314aead 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -45,7 +45,7 @@ PUBLIC int CtlConfigMagicNew() {
PUBLIC json_object* CtlConfigScan(const char *dirList, const char *prefix) {
char controlFile [CONTROL_MAXPATH_LEN];
- strncpy(controlFile, prefix, strlen(prefix));
+ strncpy(controlFile, prefix, strlen(prefix)+1);
strncat(controlFile, GetBinderName(), strlen(GetBinderName()));
// search for default dispatch config file
@@ -60,24 +60,26 @@ PUBLIC char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char
// search for default dispatch config file
json_object* responseJ = CtlConfigScan (dirList, prefix);
- // We load 1st file others are just warnings
- for (index = 0; index < json_object_array_length(responseJ); index++) {
- json_object *entryJ = json_object_array_get_idx(responseJ, index);
+ if(responseJ) {
+ // We load 1st file others are just warnings
+ for (index = 0; index < json_object_array_length(responseJ); index++) {
+ json_object *entryJ = json_object_array_get_idx(responseJ, index);
- char *filename;
- char*fullpath;
- int err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
- if (err) {
- AFB_ApiError(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ));
- return NULL;
- }
+ char *filename;
+ char*fullpath;
+ int err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
+ if (err) {
+ AFB_ApiError(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ));
+ return NULL;
+ }
- if (index == 0) {
- char filepath[CONTROL_MAXPATH_LEN];
- strncpy(filepath, fullpath, strlen(fullpath));
- strncat(filepath, "/", strlen("/"));
- strncat(filepath, filename, strlen(filename));
- return (strdup(filepath));
+ if (index == 0) {
+ char filepath[CONTROL_MAXPATH_LEN];
+ strncpy(filepath, fullpath, strlen(fullpath)+1);
+ strncat(filepath, "/", strlen("/"));
+ strncat(filepath, filename, strlen(filename));
+ return (strdup(filepath));
+ }
}
}