[FIX] buffer overflow 42/37542/1
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Mon, 30 Mar 2015 15:58:05 +0000 (18:58 +0300)
committerVitaliy Cherepanov <v.cherepanov@samsung.com>
Mon, 30 Mar 2015 15:58:05 +0000 (18:58 +0300)
overflow buf. fscanf call in find_pid_from_path.

Change-Id: Ide5c325003cc977997ac39a8ca114a12e00f112e
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
daemon/utils.c

index 2dbefae..81432d5 100644 (file)
@@ -254,13 +254,15 @@ void kill_app_web(const char *app_id)
        }
 }
 
+#define SUB_1(x) (x-1)
+#define STRDEFINE(x) #x
 // find process id from executable binary path
 static pid_t find_pid_from_path(const char *path)
 {
        char buf[BUFFER_MAX];
        char cmdline[PATH_MAX];
        DIR *proc;
-       FILE *fp;
+       FILE *fp = NULL;
        static char dirent_buffer[ sizeof(struct dirent) + PATH_MAX + 1 ] = {0,};
        static struct dirent *dirent_r = (struct dirent *)dirent_buffer;
        struct dirent *entry;
@@ -285,11 +287,10 @@ static pid_t find_pid_from_path(const char *path)
                        continue;
 
                found = 0;
-               if (fscanf(fp, "%s", buf) != EOF) /* read only argv[0] */
+               if (fscanf(fp, "%" STRDEFINE(SUB_1(BUFFER_MAX)) "s", buf) != EOF) /* read only argv[0] */
                        found = (strncmp(path, buf, len) == 0);
 
                fclose(fp);
-
                if (found)
                        goto out_close_dir;
        }