From: Ralph Corderoy Date: Sun, 10 Sep 2017 12:29:46 +0000 (+0100) Subject: get_file_info(): Don't dereference out of scope char array. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/b04d3a5bfe54b5e828a998f3e56bd97d6f82df1d?ds=inline;hp=e5479da8544d4fe47a320934667cb91c1c6a309e 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. --- 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)) {