summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-11-02 14:54:25 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:54 +0100
commit723b3c8d8d9e75ff7c1b6573cc5edd718fc05ac2 (patch)
treeb861a9958459d809b13472ace1a5612e58a23805 /ctl-lib
parent5ea27091ffd08d0c9cb9368d274bd0998fd89a77 (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')
-rw-r--r--ctl-lib/ctl-config.c14
-rw-r--r--ctl-lib/ctl-lua.c38
-rw-r--r--ctl-lib/ctl-plugin.c10
3 files changed, 31 insertions, 31 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));
}
}
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index cdb245a..25a6af9 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -804,9 +804,9 @@ STATIC void LuaDoAction (LuaDoActionT action, AFB_ReqT request) {
// search for filename=script in CONTROL_LUA_PATH
if (!luaScriptPathJ) {
- strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, sizeof(luaScriptPath));
- strncat(luaScriptPath,"-", sizeof(luaScriptPath));
- strncat(luaScriptPath,target, sizeof(luaScriptPath));
+ strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, strlen(CONTROL_DOSCRIPT_PRE));
+ strncat(luaScriptPath,"-", strlen("-"));
+ strncat(luaScriptPath,target, strlen(target));
luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,luaScriptPath,".lua");
}
for (index=0; index < json_object_array_length(luaScriptPathJ); index++) {
@@ -820,9 +820,9 @@ STATIC void LuaDoAction (LuaDoActionT action, AFB_ReqT request) {
if (index > 0) AFB_ApiWarning(source->api, "LUA-DOSCRIPT-SCAN:Ignore second script=%s path=%s", filename, fullpath);
else {
- strncpy (luaScriptPath, fullpath, sizeof(luaScriptPath));
- strncat (luaScriptPath, "/", sizeof(luaScriptPath));
- strncat (luaScriptPath, filename, sizeof(luaScriptPath));
+ strncpy (luaScriptPath, fullpath, strlen(fullpath));
+ strncat (luaScriptPath, "/", strlen("/"));
+ strncat (luaScriptPath, filename, strlen(filename));
}
}
@@ -841,8 +841,8 @@ STATIC void LuaDoAction (LuaDoActionT action, AFB_ReqT request) {
// if no func name given try to deduct from filename
if (!func && (func=(char*)GetMidleName(filename))!=NULL) {
- strncpy(luaScriptPath,"_", sizeof(luaScriptPath));
- strncat(luaScriptPath,func, sizeof(luaScriptPath));
+ strncpy(luaScriptPath,"_", strlen("_"));
+ strncat(luaScriptPath,func, strlen(func));
func=luaScriptPath;
}
if (!func) {
@@ -918,8 +918,8 @@ STATIC int LuaTimerClear (lua_State* luaState) {
// retrieve useful information opaque handle
TimerHandleT *timerHandle = LuaTimerPop(luaState, LUA_FIST_ARG);
if (!timerHandle) goto OnErrorExit;
-
-#ifdef AFB_BINDING_PREV3
+
+#ifdef AFB_BINDING_PREV3
// API handle does not exit in API-V2
LuaCbHandleT *luaCbHandle = (LuaCbHandleT*) timerHandle->context;
#endif
@@ -975,7 +975,7 @@ STATIC int LuaTimerSetCB (TimerHandleT *timer) {
count ++;
lua_pushlightuserdata(luaState, timer);
if (!afbSource) goto OnErrorExit;
-
+
// Push user Context
count+= LuaPushArgument(LuaCbHandle->source, LuaCbHandle->context);
@@ -1025,7 +1025,7 @@ STATIC int LuaTimerSet(lua_State* luaState) {
int err = wrap_json_unpack(timerJ, "{ss, s?s si, si !}", "uid", &uid, "info", &info, "delay", &delay, "count", &count);
if (err) {
-
+
lua_pushliteral(luaState, "LuaTimerSet: Syntax timerT={uid:xxx delay:ms, count:xx}");
goto OnErrorExit;
}
@@ -1269,10 +1269,10 @@ PUBLIC int LuaConfigExec (AFB_ApiT apiHandle, const char* prefix) {
// search for default policy config files
char fullprefix[CONTROL_MAXPATH_LEN];
- strncpy (fullprefix, prefix, sizeof(fullprefix));
- strncat (fullprefix, "-", sizeof(fullprefix));
- strncat (fullprefix, GetBinderName(), sizeof(fullprefix));
- strncat (fullprefix, "-", sizeof(fullprefix));
+ strncpy (fullprefix, prefix, strlen(prefix));
+ strncat (fullprefix, "-", strlen("-"));
+ strncat (fullprefix, GetBinderName(), strlen(GetBinderName()));
+ strncat (fullprefix, "-", strlen("-"));
const char *dirList= getenv("CONTROL_LUA_PATH");
if (!dirList) dirList=CONTROL_LUA_PATH;
@@ -1296,9 +1296,9 @@ PUBLIC int LuaConfigExec (AFB_ApiT apiHandle, const char* prefix) {
}
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));
err= luaL_loadfile(luaState, filepath);
if (err) {
AFB_ApiError(apiHandle, "LUA-LOAD HOOPs Error in LUA loading scripts=%s err=%s", filepath, lua_tostring(luaState,-1));
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index 4d9414f..1304984 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -119,9 +119,9 @@ STATIC int PluginLoadOne (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object
}
char pluginpath[CONTROL_MAXPATH_LEN];
- strncpy(pluginpath, fullpath, sizeof (pluginpath));
- strncat(pluginpath, "/", sizeof (pluginpath));
- strncat(pluginpath, filename, sizeof (pluginpath));
+ strncpy(pluginpath, fullpath, strlen (fullpath));
+ strncat(pluginpath, "/", strlen ("/"));
+ strncat(pluginpath, filename, strlen (filename));
dlHandle = dlopen(pluginpath, RTLD_NOW);
if (!dlHandle) {
AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Fail to load pluginpath=%s err= %s", pluginpath, dlerror());
@@ -156,8 +156,8 @@ STATIC int PluginLoadOne (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object
int Lua2cAddOne(luaL_Reg *l2cFunc, const char* l2cName, int index) {
char funcName[CONTROL_MAXPATH_LEN];
- strncpy(funcName, "lua2c_", sizeof (funcName));
- strncat(funcName, l2cName, sizeof (funcName));
+ strncpy(funcName, "lua2c_", strlen ("lua2c_"));
+ strncat(funcName, l2cName, strlen (l2cName));
Lua2cFunctionT l2cFunction = (Lua2cFunctionT) dlsym(dlHandle, funcName);
if (!l2cFunction) {