aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-config.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-11-02 14:54:25 +0100
committerRonan Le Martret <ronan.lemartret@iot.bzh>2017-11-24 10:38:06 +0100
commit3a6421c3dfd6b69b2fc0694a39754f9cb096474c (patch)
treeb861a9958459d809b13472ace1a5612e58a23805 /ctl-lib/ctl-config.c
parent3e6dbb17336cade4abf270193c164ea60b7b8389 (diff)
fix: wrong usage of strncat and strncpy function
3rd arguments match strlen of 2nd arguments and should not match the maximum length of destination variable. Change-Id: Ifebf6097bb995d0cf2c5633eb94d52d4517ade7b Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-config.c')
-rw-r--r--ctl-lib/ctl-config.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index 2056f09..c315f9c 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -45,8 +45,8 @@ PUBLIC int CtlConfigMagicNew() {
PUBLIC json_object* CtlConfigScan(const char *dirList, const char *prefix) {
char controlFile [CONTROL_MAXPATH_LEN];
- strncpy(controlFile, prefix, CONTROL_MAXPATH_LEN);
- strncat(controlFile, GetBinderName(), CONTROL_MAXPATH_LEN);
+ strncpy(controlFile, prefix, strlen(prefix));
+ strncat(controlFile, GetBinderName(), strlen(GetBinderName()));
// search for default dispatch config file
json_object* responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, controlFile, ".json");
@@ -55,7 +55,7 @@ PUBLIC json_object* CtlConfigScan(const char *dirList, const char *prefix) {
}
PUBLIC char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) {
- int index, err;
+ int index;
// search for default dispatch config file
json_object* responseJ = CtlConfigScan (dirList, prefix);
@@ -66,7 +66,7 @@ PUBLIC char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char
char *filename;
char*fullpath;
- err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
+ 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;
@@ -74,9 +74,9 @@ PUBLIC char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char
if (index == 0) {
char filepath[CONTROL_MAXPATH_LEN];
- strncpy(filepath, fullpath, sizeof (filepath));
- strncat(filepath, "/", sizeof (filepath));
- strncat(filepath, filename, sizeof (filepath));
+ strncpy(filepath, fullpath, strlen(fullpath));
+ strncat(filepath, "/", strlen("/"));
+ strncat(filepath, filename, strlen(filename));
return (strdup(filepath));
}
}