From 723b3c8d8d9e75ff7c1b6573cc5edd718fc05ac2 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 2 Nov 2017 14:54:25 +0100 Subject: 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 --- ctl-lib/ctl-config.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ctl-lib/ctl-config.c') 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)); } } -- cgit 1.2.3-korg