summaryrefslogtreecommitdiffstats
path: root/ctl-binding/ctl-dispatch.c
diff options
context:
space:
mode:
authorRonan Le Martret <ronan.lemartret@iot.bzh>2017-08-29 16:07:56 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:25 +0100
commite572871c06b7d04722d56becf7ef8ad86b14124c (patch)
tree167729220b3ca98148183382fd64668287f902d9 /ctl-binding/ctl-dispatch.c
parentd60bc482a611e31da6e0b78b6e482ee270635891 (diff)
Fix strncat funct
I: Statement might be overflowing a buffer in strncat. Common mistake: BAD: strncat(buffer,charptr,sizeof(buffer)) is wrong, it takes the left over size as 3rd argument GOOD: strncat(buffer,charptr,sizeof(buffer)-strlen(buffer)-1) Signed-off-by: Ronan Le Martret <ronan.lemartret@iot.bzh>
Diffstat (limited to 'ctl-binding/ctl-dispatch.c')
-rw-r--r--ctl-binding/ctl-dispatch.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ctl-binding/ctl-dispatch.c b/ctl-binding/ctl-dispatch.c
index fe31a55..da900ec 100644
--- a/ctl-binding/ctl-dispatch.c
+++ b/ctl-binding/ctl-dispatch.c
@@ -421,8 +421,8 @@ STATIC DispatchHandleT *DispatchLoadOnload(DispatchConfigT *controlConfig, json_
char pluginpath[CONTROL_MAXPATH_LEN];
strncpy(pluginpath, fullpath, sizeof (pluginpath));
- strncat(pluginpath, "/", sizeof (pluginpath));
- strncat(pluginpath, filename, sizeof (pluginpath));
+ strncat(pluginpath, "/", sizeof (pluginpath)-strlen(pluginpath)-1);
+ strncat(pluginpath, filename, sizeof (pluginpath)-strlen(pluginpath)-1);
dPlugin->dlHandle = dlopen(pluginpath, RTLD_NOW);
if (!dPlugin->dlHandle) {
AFB_ERROR("DISPATCH-LOAD-CONFIG:PLUGIN Fail to load pluginpath=%s err= %s", pluginpath, dlerror());
@@ -453,7 +453,7 @@ STATIC DispatchHandleT *DispatchLoadOnload(DispatchConfigT *controlConfig, json_
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));
+ strncat(funcName, l2cName, sizeof(funcName)-strlen(funcName)-1);
Lua2cFunctionT l2cFunction= (Lua2cFunctionT)dlsym(dPlugin->dlHandle, funcName);
if (!l2cFunction) {
@@ -625,7 +625,7 @@ PUBLIC int DispatchInit() {
if (!dirList) dirList=CONTROL_CONFIG_PATH;
strncpy(controlFile, CONTROL_CONFIG_PRE "-", CONTROL_MAXPATH_LEN);
- strncat(controlFile, GetBinderName(), CONTROL_MAXPATH_LEN);
+ strncat(controlFile, GetBinderName(), CONTROL_MAXPATH_LEN-strlen(controlFile)-1);
// search for default dispatch config file
json_object* responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, controlFile, "json");
@@ -646,8 +646,8 @@ PUBLIC int DispatchInit() {
if (strcasestr(filename, controlFile)) {
char filepath[CONTROL_MAXPATH_LEN];
strncpy(filepath, fullpath, sizeof (filepath));
- strncat(filepath, "/", sizeof (filepath));
- strncat(filepath, filename, sizeof (filepath));
+ strncat(filepath, "/", sizeof (filepath)-strlen(filepath)-1);
+ strncat(filepath, filename, sizeof (filepath)-strlen(filepath)-1);
configHandle = DispatchLoadConfig(filepath);
if (!configHandle) {
AFB_ERROR("DISPATCH-INIT:ERROR Fail loading [%s]", filepath);