From b04d3a5bfe54b5e828a998f3e56bd97d6f82df1d Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Sun, 10 Sep 2017 13:29:46 +0100 Subject: [PATCH] get_file_info(): Don't dereference out of scope char array. A pointer to `char buf[...]' is taken, the array being declared in a block scope inside the function. The pointer is passed to strdup(3) as the function returned, but the array is by then out of scope. Move the array to the function's scope. Fixes 0c50c669. --- sbr/mime_type.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbr/mime_type.c b/sbr/mime_type.c index f1b96fe5..25928500 100644 --- a/sbr/mime_type.c +++ b/sbr/mime_type.c @@ -117,6 +117,7 @@ static char * get_file_info(const char *proc, const char *file_name) { char *cmd, *cp; char *quotec = "'"; + char buf[max(BUFSIZ, 2048)]; if ((cp = strchr(file_name, '\''))) { /* file_name contains a single quote. */ @@ -132,7 +133,6 @@ get_file_info(const char *proc, const char *file_name) { FILE *fp; if ((fp = popen(cmd, "r")) != NULL) { - char buf[max(BUFSIZ, 2048)]; buf[0] = '\0'; if (fgets(buf, sizeof buf, fp)) { -- 2.56.0