From: André Malo Date: Mon, 17 May 2004 23:36:15 +0000 (+0000) Subject: external map responses were cut at 2048 bytes (and possibly got out of sync that X-Git-Tag: pre_ajp_proxy~253 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7480ab8ebe8793ad7cf437b0552fa1a44ef44f98;p=apache external map responses were cut at 2048 bytes (and possibly got out of sync that way). Now they are unlimited. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@103691 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 4bfab9e0c2..04a82fd934 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) External rewrite map responses are no longer limited to 2048 + bytes. [André Malo] + *) Fix a potential SEGV in the 'shmcb' session cache when session data size is greater than the size of the cache. PR 27751 [Geoff Thorpe ] diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 10391d2e21..ca51ce378f 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -182,9 +182,9 @@ #define REWRITE_MAX_TXT_MAP_LINE 1024 #endif -/* max response length (incl.\n) in prg rewrite maps */ -#ifndef REWRITE_MAX_PRG_MAP_LINE -#define REWRITE_MAX_PRG_MAP_LINE 2048 +/* buffer length for prg rewrite maps */ +#ifndef REWRITE_PRG_MAP_BUF +#define REWRITE_PRG_MAP_BUF 1024 #endif /* for better readbility */ @@ -1314,13 +1314,13 @@ static char *lookup_map_dbmfile(request_rec *r, const char *file, static char *lookup_map_program(request_rec *r, apr_file_t *fpin, apr_file_t *fpout, char *key) { - char buf[REWRITE_MAX_PRG_MAP_LINE]; + char *buf; char c; - apr_size_t i; - apr_size_t nbytes; + apr_size_t i, nbytes, combined_len = 0; apr_status_t rv; const char *eol = APR_EOL_STR; - int eolc = 0; + int eolc = 0, found_nl = 0; + result_list *buflist = NULL, *curbuf = NULL; #ifndef NO_WRITEV struct iovec iova[2]; @@ -1368,31 +1368,90 @@ static char *lookup_map_program(request_rec *r, apr_file_t *fpin, apr_file_writev(fpin, iova, niov, &nbytes); #endif + buf = apr_palloc(r->pool, REWRITE_PRG_MAP_BUF + 1); + /* read in the response value */ - i = 0; nbytes = 1; apr_file_read(fpout, &c, &nbytes); - while (nbytes == 1 && (i < REWRITE_MAX_PRG_MAP_LINE)) { - if (c == eol[eolc]) { - if (!eol[++eolc]) { - /* remove eol from the buffer */ - i -= --eolc; + do { + i = 0; + while (nbytes == 1 && (i < REWRITE_PRG_MAP_BUF)) { + if (c == eol[eolc]) { + if (!eol[++eolc]) { + /* remove eol from the buffer */ + --eolc; + if (i < eolc) { + curbuf->len -= eolc-i; + i = 0; + } + else { + i -= eolc; + } + ++found_nl; + break; + } + } + + /* only partial (invalid) eol sequence -> reset the counter */ + else if (eolc) { + eolc = 0; + } + + /* catch binary mode, e.g. on Win32 */ + else if (c == '\n') { + ++found_nl; break; } - } - /* only partial (invalid) eol sequence -> reset the counter */ - else if (eolc) { - eolc = 0; + buf[i++] = c; + apr_file_read(fpout, &c, &nbytes); } - /* catch binary mode, e.g. on Win32 */ - else if (c == '\n') { - break; + /* well, if there wasn't a newline yet, we need to read further */ + if (buflist || (nbytes == 1 && !found_nl)) { + if (!buflist) { + curbuf = buflist = apr_palloc(r->pool, sizeof(*buflist)); + } + else if (i) { + curbuf->next = apr_palloc(r->pool, sizeof(*buflist)); + curbuf = curbuf->next; + + } + curbuf->next = NULL; + + if (i) { + curbuf->string = buf; + curbuf->len = i; + combined_len += i; + buf = apr_palloc(r->pool, REWRITE_PRG_MAP_BUF); + } + + if (nbytes == 1 && !found_nl) { + i = 0; + continue; + } } - buf[i++] = c; - apr_file_read(fpout, &c, &nbytes); + break; + } while (1); + + /* concat the stuff */ + if (buflist) { + char *p; + + p = buf = apr_palloc(r->pool, combined_len + 1); /* \0 */ + while (buflist) { + if (buflist->len) { + memcpy(p, buflist->string, buflist->len); + p += buflist->len; + } + buflist = buflist->next; + } + *p = '\0'; + i = combined_len; + } + else { + buf[i] = '\0'; } /* give the lock back */ @@ -1406,12 +1465,12 @@ static char *lookup_map_program(request_rec *r, apr_file_t *fpin, } } - /* buf is not zero terminated, so be careful! */ - if (i == 4 && strncasecmp(buf, "NULL", 4) == 0) { + /* catch the "failed" case */ + if (i == 4 && !strcasecmp(buf, "NULL")) { return NULL; } - return apr_pstrmemdup(r->pool, buf, i); + return buf; } /*