fix strncat funct
authorRonan Le Martret <ronan.lemartret@iot.bzh>
Tue, 29 Aug 2017 14:09:07 +0000 (16:09 +0200)
committerRonan Le Martret <ronan.lemartret@iot.bzh>
Tue, 29 Aug 2017 14:10:29 +0000 (16:10 +0200)
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>
filescan-utils.c

index e735682..f1de9d0 100644 (file)
@@ -49,8 +49,8 @@ PUBLIC json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode,
                 if (dirEnt->d_name[0]=='.' || dirEnt->d_name[0]=='_') continue;
 
                 strncpy(newpath, searchPath, sizeof(newpath));
-                strncat(newpath, "/", sizeof(newpath));
-                strncat(newpath, dirEnt->d_name, sizeof(newpath));
+                strncat(newpath, "/", sizeof(newpath)-strlen(newpath)-1);
+                strncat(newpath, dirEnt->d_name, sizeof(newpath)-strlen(newpath)-1);
                 ScanDir(newpath);
                 continue;
             }