From: Ruediger Pluem Date: Mon, 19 Oct 2009 19:22:55 +0000 (+0000) Subject: * Reduce memory consumption when processing very long lines by at least X-Git-Tag: 2.3.3~149 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5f9bd3e7c861b2db8f9620850ea7a4eea1c1778a;p=thirdparty%2Fapache%2Fhttpd.git * Reduce memory consumption when processing very long lines by at least doubleing the size of the new buffer each time. PR: 48024 Submitted by: Basant Kumar Kukreja Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@826772 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index cee9e511029..6973be23194 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Changes with Apache 2.3.3 mod_proxy_ftp: NULL pointer dereference on error paths. [Stefan Fritsch , Joe Orton] + *) mod_sed: Reduce memory consumption when processing very long lines. + PR 48024 [Basant Kumar Kukreja ] + *) ab: Fix segfault in case the argument for -n is a very large number. PR 47178. [Philipp Hagemeister ] diff --git a/modules/filters/sed1.c b/modules/filters/sed1.c index 24f16f05018..af26065365f 100644 --- a/modules/filters/sed1.c +++ b/modules/filters/sed1.c @@ -99,6 +99,12 @@ static void grow_buffer(apr_pool_t *pool, char **buffer, int spendsize = 0; if (*cursize >= newsize) return; + /* Avoid number of times realloc is called. It could cause huge memory + * requirement if line size is huge e.g 2 MB */ + if (newsize < *cursize * 2) { + newsize = *cursize * 2; + } + /* Align it to 4 KB boundary */ newsize = (newsize + ((1 << 12) - 1)) & ~((1 << 12) -1); newbuffer = apr_pcalloc(pool, newsize);