From 281fd7e5abaaad4304a7299ff4c2cad210c1c46d Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 12 Aug 2015 10:34:21 +0000 Subject: [PATCH] execute_external_filter(): Don't rely on undefined malloc() behaviour ... and fix the read buffer scaling for initial sizes below READ_LENGTH. Could fix the crash reported by Jonathan McKenzie on ijbswa-users@ --- filters.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/filters.c b/filters.c index 1fc1c476..d3dcaeb3 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.191 2014/10/18 11:28:36 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.192 2014/10/18 11:30:24 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -1871,7 +1871,8 @@ static char *execute_external_filter(const struct client_state *csp, return NULL; } - filter_output = malloc_or_die(*size); + /* Allocate at least one byte */ + filter_output = malloc_or_die(*size + 1); new_size = 0; while (!feof(fp) && !ferror(fp)) @@ -1885,7 +1886,7 @@ static char *execute_external_filter(const struct client_state *csp, char *p; /* Could be considered wasteful if the content is 'large'. */ - *size = (*size != 0) ? *size * 2 : READ_LENGTH; + *size = (*size > READ_LENGTH) ? *size * 2 : READ_LENGTH; p = realloc(filter_output, *size); if (p == NULL) -- 2.39.2