overflow buf. fscanf call in find_pid_from_path.
Change-Id: Ide5c325003cc977997ac39a8ca114a12e00f112e
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
}
}
+#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;
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;
}