diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-11-03 15:42:26 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-12-13 15:02:54 +0100 |
commit | 25b02ddcd940fbf2f19d0012309d7945c389861c (patch) | |
tree | 735dfc4b2dc21af14cf2f948ef8dfe37888dd899 /ctl-lib/ctl-config.c | |
parent | 644db20dec0db50c857e5420ba731528dfff87e1 (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.c | 36 |
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)); + } } } |