From: Romain Forlot <romain.forlot@iot.bzh>
Date: Fri, 11 May 2018 08:50:03 +0000 (+0200)
Subject: Fix: wrong searchPath parameter
X-Git-Tag: 5.99.1~18
X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=70fd3f0ea563220211a5b412ebdab46eb0ce5ed4;p=apps%2Fapp-afb-helpers-submodule.git

Fix: wrong searchPath parameter

Change initialization parts of the function to be clearer
and ensure that at least searchPath has been correctly passed

Change-Id: Ic055e2c244b261b33960072f51193fcbbd48c222
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
---

diff --git a/filescan-utils.c b/filescan-utils.c
index fbcdc64..70ca6ff 100644
--- a/filescan-utils.c
+++ b/filescan-utils.c
@@ -28,12 +28,17 @@
 
 // List Avaliable Configuration Files
 json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode, const char *prefix, const char *extention) {
-    json_object *responseJ;
+    json_object *responseJ = json_object_new_array();
     char *dirPath;
-    char* dirList= strdup(searchPath);
+    char* dirList;
     size_t extentionLen=0;
     int count=0;
 
+    if(!searchPath)
+        return responseJ;
+
+    dirList = strdup(searchPath);
+
     int ScanDir (char *searchPath) {
         int found=0;
         DIR  *dirHandle;
@@ -79,8 +84,8 @@ json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode, const
         return found;
     }
 
-    if (extention) extentionLen=strlen(extention);
-    responseJ = json_object_new_array();
+    if (extention)
+        extentionLen=strlen(extention);
 
     // loop recursively on dir
     for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
@@ -140,7 +145,7 @@ char *GetBindingDirPath(struct afb_dynapi *dynapi)
     if(dynapi)
         sprintf(fd_link, "/proc/self/fd/%d", afb_dynapi_rootdir_get_fd(dynapi));
     else
-        sprintf(fd_link, "/proc/self/fd/%d", afb_daemon_rootdir_get_fd_v2());
+        sprintf(fd_link, "/proc/self/fd/%d", afb_daemon_rootdir_get_fd());
 
     if((len = readlink(fd_link, retdir, sizeof(retdir)-1)) == -1)
     {