--------------------- PatchSet 10246 Date: 2007/12/15 05:17:57 Author: adri Branch: s27_adri Tag: (none) Log: html_quote() now takes a len parameter and doesn't expect a NUL terminated string; convert the code over to use this. Members: include/util.h:1.17.20.1->1.17.20.2 lib/html_quote.c:1.4->1.4.58.1 src/errorpage.c:1.37.6.1.4.1->1.37.6.1.4.2 src/ftp.c:1.44.4.2.4.4->1.44.4.2.4.5 src/gopher.c:1.26.12.2->1.26.12.3 Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.17.20.1 retrieving revision 1.17.20.2 diff -u -r1.17.20.1 -r1.17.20.2 --- squid/include/util.h 14 Dec 2007 06:11:26 -0000 1.17.20.1 +++ squid/include/util.h 15 Dec 2007 05:17:57 -0000 1.17.20.2 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.17.20.1 2007/12/14 06:11:26 adri Exp $ + * $Id: util.h,v 1.17.20.2 2007/12/15 05:17:57 adri Exp $ * * AUTHOR: Harvest Derived * @@ -84,7 +84,7 @@ extern void rfc1738_unescape(char *); /* html.c */ -extern char *html_quote(const char *); +extern char *html_quote(const char *, int); #if XMALLOC_STATISTICS extern void malloc_statistics(void (*)(int, int, int, void *), void *); Index: squid/lib/html_quote.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/html_quote.c,v retrieving revision 1.4 retrieving revision 1.4.58.1 diff -u -r1.4 -r1.4.58.1 --- squid/lib/html_quote.c 28 Apr 2006 11:10:49 -0000 1.4 +++ squid/lib/html_quote.c 15 Dec 2007 05:17:57 -0000 1.4.58.1 @@ -81,23 +81,23 @@ * string. */ char * -html_quote(const char *string) +html_quote(const char *string, int len) { static char *buf; static size_t bufsize = 0; const char *src; char *dst; - int i; + int i, j; /* XXX This really should be implemented using a MemPool, but * MemPools are not yet available in lib... */ - if (buf == NULL || strlen(string) * 6 > bufsize) { + if (buf == NULL || len * 6 > bufsize) { xfree(buf); - bufsize = strlen(string) * 6 + 1; + bufsize = len * 6 + 1; buf = xcalloc(bufsize, 1); } - for (src = string, dst = buf; *src; src++) { + for (j = 0, src = string, dst = buf; j < len; j++, src++) { const char *escape = NULL; const unsigned char ch = *src; Index: squid/src/errorpage.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/errorpage.c,v retrieving revision 1.37.6.1.4.1 retrieving revision 1.37.6.1.4.2 diff -u -r1.37.6.1.4.1 -r1.37.6.1.4.2 --- squid/src/errorpage.c 13 Dec 2007 14:17:52 -0000 1.37.6.1.4.1 +++ squid/src/errorpage.c 15 Dec 2007 05:17:57 -0000 1.37.6.1.4.2 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.c,v 1.37.6.1.4.1 2007/12/13 14:17:52 adri Exp $ + * $Id: errorpage.c,v 1.37.6.1.4.2 2007/12/15 05:17:57 adri Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -616,7 +616,7 @@ assert(p); debug(4, 3) ("errorConvert: %%%c --> '%s'\n", token, p); if (do_quote) - p = html_quote(p); + p = html_quote(p, strlen(p)); return p; } Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.44.4.2.4.4 retrieving revision 1.44.4.2.4.5 diff -u -r1.44.4.2.4.4 -r1.44.4.2.4.5 --- squid/src/ftp.c 14 Dec 2007 02:48:36 -0000 1.44.4.2.4.4 +++ squid/src/ftp.c 15 Dec 2007 05:17:57 -0000 1.44.4.2.4.5 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.44.4.2.4.4 2007/12/14 02:48:36 adri Exp $ + * $Id: ftp.c,v 1.44.4.2.4.5 2007/12/15 05:17:57 adri Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -369,19 +369,19 @@ { char *t = xstrdup(title); rfc1738_unescape(t); - storeAppendPrintf(e, "FTP Directory: %s\n", html_quote(t)); + storeAppendPrintf(e, "FTP Directory: %s\n", html_quote(t, strlen(t))); xfree(t); } storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "\n"); if (ftpState->flags.use_base) storeAppendPrintf(e, "\n", - html_quote(strBuf(ftpState->base_href))); + html_quote(strBuf2(ftpState->base_href), strLen2(ftpState->base_href))); storeAppendPrintf(e, "\n"); if (ftpState->cwd_message) { storeAppendPrintf(e, "
\n");
 	for (w = ftpState->cwd_message; w; w = w->next)
-	    storeAppendPrintf(e, "%s\n", html_quote(w->key));
+	    storeAppendPrintf(e, "%s\n", html_quote(w->key, strlen(w->key)));
 	storeAppendPrintf(e, "
\n"); storeAppendPrintf(e, "
\n"); wordlistDestroy(&ftpState->cwd_message); @@ -396,9 +396,9 @@ if (i > j) { char *url = xstrdup(title); url[i] = '\0'; - storeAppendPrintf(e, "", html_quote(url + k)); + storeAppendPrintf(e, "", html_quote(url + k, strlen(url + k))); rfc1738_unescape(url + j); - storeAppendPrintf(e, "%s", html_quote(url + j)); + storeAppendPrintf(e, "%s", html_quote(url + j, strlen(url + j))); safe_free(url); } storeAppendPrintf(e, "/"); @@ -407,7 +407,7 @@ if (i == j) { /* Error guard, or "assert" */ storeAppendPrintf(e, "ERROR: Failed to parse URL: %s\n", - html_quote(title)); + html_quote(title, strlen(title))); debug(9, 0) ("Failed to parse URL: %s\n", title); break; } @@ -764,10 +764,11 @@ "[LINK]"); /* sometimes there is an 'l' flag, but no "->" link */ if (parts->link) { - char *link2 = xstrdup(html_quote(rfc1738_escape(parts->link))); + char *e = rfc1738_escape(parts->link); + char *link2 = xstrdup(html_quote(e, strlen(e))); snprintf(link, 2048, " -> %s", *link2 != '/' ? prefix : "", link2, - html_quote(parts->link)); + html_quote(parts->link, strlen(parts->link))); safe_free(link2); } break; @@ -820,13 +821,13 @@ if (parts->type != '\0') { snprintf(html, 8192, "%s %s%s " "%s%8s%s%s%s%s\n", - prefix, href, icon, prefix, href, html_quote(text), dots_fill(strlen(text)), + prefix, href, icon, prefix, href, html_quote(text, strlen(text)), dots_fill(strlen(text)), parts->date, size, chdir, view, download, link); } else { /* Plain listing. {icon} {text} ... {chdir}{view}{download} */ snprintf(html, 8192, "%s %s%s " "%s%s%s%s\n", - prefix, href, icon, prefix, href, html_quote(text), dots_fill(strlen(text)), + prefix, href, icon, prefix, href, html_quote(text, strlen(text)), dots_fill(strlen(text)), chdir, view, download, link); } ftpListPartsFree(&parts); Index: squid/src/gopher.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/gopher.c,v retrieving revision 1.26.12.2 retrieving revision 1.26.12.3 diff -u -r1.26.12.2 -r1.26.12.3 --- squid/src/gopher.c 13 Dec 2007 14:01:46 -0000 1.26.12.2 +++ squid/src/gopher.c 15 Dec 2007 05:17:57 -0000 1.26.12.3 @@ -1,6 +1,6 @@ /* - * $Id: gopher.c,v 1.26.12.2 2007/12/13 14:01:46 adri Exp $ + * $Id: gopher.c,v 1.26.12.3 2007/12/15 05:17:57 adri Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -289,7 +289,7 @@ entry = gopherState->entry; if (gopherState->conversion == HTML_INDEX_PAGE) { - char *html_url = html_quote(storeUrl(entry)); + char *html_url = html_quote(storeUrl(entry), strlen(storeUrl(entry))); gopherHTMLHeader(entry, "Gopher Index %s", html_url); storeAppendPrintf(entry, "

This is a searchable Gopher index. Use the search\n" @@ -302,7 +302,7 @@ return; } if (gopherState->conversion == HTML_CSO_PAGE) { - char *html_url = html_quote(storeUrl(entry)); + char *html_url = html_quote(storeUrl(entry), strlen(storeUrl(entry))); gopherHTMLHeader(entry, "CSO Search of %s", html_url); storeAppendPrintf(entry, "

A CSO database usually contains a phonebook or\n" @@ -476,23 +476,23 @@ if (strlen(escaped_selector) != 0) snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n", icon_url, escaped_selector, rfc1738_escape_part(host), - *port ? ":" : "", port, html_quote(name)); + *port ? ":" : "", port, html_quote(name, strlen(name))); else snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n", icon_url, rfc1738_escape_part(host), *port ? ":" : "", - port, html_quote(name)); + port, html_quote(name, strlen(name))); } else if (gtype == GOPHER_INFO) { - snprintf(tmpbuf, TEMP_BUF_SIZE, "\t%s\n", html_quote(name)); + snprintf(tmpbuf, TEMP_BUF_SIZE, "\t%s\n", html_quote(name, strlen(name))); } else { if (strncmp(selector, "GET /", 5) == 0) { /* WWW link */ snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n", - icon_url, host, rfc1738_escape_unescaped(selector + 5), html_quote(name)); + icon_url, host, rfc1738_escape_unescaped(selector + 5), html_quote(name, strlen(name))); } else { /* Standard link */ snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n", - icon_url, host, gtype, rfc1738_escape(selector), html_quote(name)); + icon_url, host, gtype, rfc1738_escape(selector), html_quote(name, strlen(name))); } } safe_free(escaped_selector); @@ -528,10 +528,10 @@ break; if (gopherState->cso_recno != recno) { - snprintf(tmpbuf, TEMP_BUF_SIZE, "


Record# %d
%s

\n
", recno, html_quote(result));
+			snprintf(tmpbuf, TEMP_BUF_SIZE, "

Record# %d
%s

\n
", recno, html_quote(result, strlen(result)));
 			gopherState->cso_recno = recno;
 		    } else {
-			snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result));
+			snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result, strlen(result)));
 		    }
 		    strCat(outbuf, tmpbuf);
 		    break;
@@ -559,7 +559,7 @@
 		    case 502:	/* Too Many Matches */
 			{
 			    /* Print the message the server returns */
-			    snprintf(tmpbuf, TEMP_BUF_SIZE, "

%s

\n
", html_quote(result));
+			    snprintf(tmpbuf, TEMP_BUF_SIZE, "

%s

\n
", html_quote(result, strlen(result)));
 			    strCat(outbuf, tmpbuf);
 			    break;
 			}