diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-11-03 15:42:26 +0100 |
---|---|---|
committer | Ronan Le Martret <ronan.lemartret@iot.bzh> | 2017-11-24 10:38:06 +0100 |
commit | af19faae21bf209515dcb220a102b4adf7f5b7d5 (patch) | |
tree | 735dfc4b2dc21af14cf2f948ef8dfe37888dd899 /ctl-lib/ctl-lua.c | |
parent | 19fd8c1f4b4d54d5dc2c4f586baed04e220142b1 (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-lua.c')
-rw-r--r-- | ctl-lib/ctl-lua.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 25a6af9..07b26bf 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -804,7 +804,7 @@ STATIC void LuaDoAction (LuaDoActionT action, AFB_ReqT request) { // search for filename=script in CONTROL_LUA_PATH if (!luaScriptPathJ) { - strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, strlen(CONTROL_DOSCRIPT_PRE)); + strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, strlen(CONTROL_DOSCRIPT_PRE)+1); strncat(luaScriptPath,"-", strlen("-")); strncat(luaScriptPath,target, strlen(target)); luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,luaScriptPath,".lua"); @@ -820,7 +820,7 @@ 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, strlen(fullpath)); + strncpy (luaScriptPath, fullpath, strlen(fullpath)+1); strncat (luaScriptPath, "/", strlen("/")); strncat (luaScriptPath, filename, strlen(filename)); } @@ -841,7 +841,7 @@ 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,"_", strlen("_")); + strncpy(luaScriptPath,"_", strlen("_")+1); strncat(luaScriptPath,func, strlen(func)); func=luaScriptPath; } @@ -1269,7 +1269,7 @@ PUBLIC int LuaConfigExec (AFB_ApiT apiHandle, const char* prefix) { // search for default policy config files char fullprefix[CONTROL_MAXPATH_LEN]; - strncpy (fullprefix, prefix, strlen(prefix)); + strncpy (fullprefix, prefix, strlen(prefix)+1); strncat (fullprefix, "-", strlen("-")); strncat (fullprefix, GetBinderName(), strlen(GetBinderName())); strncat (fullprefix, "-", strlen("-")); @@ -1296,7 +1296,7 @@ PUBLIC int LuaConfigExec (AFB_ApiT apiHandle, const char* prefix) { } char filepath[CONTROL_MAXPATH_LEN]; - strncpy(filepath, fullpath, strlen(fullpath)); + strncpy(filepath, fullpath, strlen(fullpath)+1); strncat(filepath, "/", strlen("/")); strncat(filepath, filename, strlen(filename)); err= luaL_loadfile(luaState, filepath); |