--------------------- PatchSet 10203 Date: 2007/12/10 08:56:50 Author: adri Branch: s27_adri Tag: (none) Log: Part of the "make Strings not require terminating-NULs" work. Create a pair of string duplicate to C string operators which may or make not take an offset. Use these in place of char * foo = xstrdup(strBuf(s)). Members: libbuf/String.c:1.1.2.5->1.1.2.6 libbuf/String.h:1.1.2.5->1.1.2.6 src/acl.c:1.90->1.90.12.1 src/client_side.c:1.202.2.9->1.202.2.9.4.1 src/ftp.c:1.44.4.2.4.1->1.44.4.2.4.2 src/http.c:1.63.2.3->1.63.2.3.4.1 src/squid.h:1.36.24.6->1.36.24.7 src/store.c:1.49.4.3->1.49.4.3.4.1 src/store_update.c:1.2.4.3->1.2.4.3.4.1 src/urn.c:1.24.6.2.4.1->1.24.6.2.4.2 Index: squid/libbuf/String.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.c,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/libbuf/String.c 9 Dec 2007 04:55:21 -0000 1.1.2.5 +++ squid/libbuf/String.c 10 Dec 2007 08:56:50 -0000 1.1.2.6 @@ -1,6 +1,6 @@ /* - * $Id: String.c,v 1.1.2.5 2007/12/09 04:55:21 adri Exp $ + * $Id: String.c,v 1.1.2.6 2007/12/10 08:56:50 adri Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -38,6 +38,8 @@ #include #include +#include "../include/config.h" +#include "../include/util.h" #include "../libcore/tools.h" #include "../libcore/varargs.h" #include "../libcore/debug.h" Index: squid/libbuf/String.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.h,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/libbuf/String.h 9 Dec 2007 04:55:21 -0000 1.1.2.5 +++ squid/libbuf/String.h 10 Dec 2007 08:56:50 -0000 1.1.2.6 @@ -22,6 +22,24 @@ return buf_buf(s.nb); } +/* These are "replacements" for strBuf and strLen which indicate that the + * code using them has been changed to not assume NUL-terminated strings */ +#define strBuf2(s) strBuf(s) +#define strLen2(s) strLen(s) + +static char * +strCDupOffset(String s, int offset) +{ + char *a = xmalloc(strLen2(s) - offset + 1); + memcpy(a, strBuf2(s), strLen2(s) - offset); + a[strLen2(s) - offset] = '\0'; + return a; + +} + +#define strCDup(s) strCDupOffset((s), 0) + +/* XXX None of these functions are non-NUL safe and they need to be later replaced */ #define strStr(s,str) ((const char*)strstr(strBuf(s), (str))) #define strCmp(s,str) strcmp(strBuf(s), (str)) #define strNCmp(s,str,n) strncmp(strBuf(s), (str), (n)) Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.90 retrieving revision 1.90.12.1 diff -u -r1.90 -r1.90.12.1 --- squid/src/acl.c 14 Mar 2007 22:51:46 -0000 1.90 +++ squid/src/acl.c 10 Dec 2007 08:56:50 -0000 1.90.12.1 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.90 2007/03/14 22:51:46 squidadm Exp $ + * $Id: acl.c,v 1.90.12.1 2007/12/10 08:56:50 adri Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -1867,7 +1867,7 @@ return aclMatchTime(ae->data, squid_curtime); /* NOTREACHED */ case ACL_URLPATH_REGEX: - esc_buf = xstrdup(strBuf(r->urlpath)); + esc_buf = strCDup(r->urlpath); rfc1738_unescape(esc_buf); k = aclMatchRegex(ae->data, esc_buf); safe_free(esc_buf); Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9 retrieving revision 1.202.2.9.4.1 diff -u -r1.202.2.9 -r1.202.2.9.4.1 --- squid/src/client_side.c 27 Nov 2007 12:16:58 -0000 1.202.2.9 +++ squid/src/client_side.c 10 Dec 2007 08:56:51 -0000 1.202.2.9.4.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9 2007/11/27 12:16:58 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.1 2007/12/10 08:56:51 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -3475,7 +3475,7 @@ http->entry->mem_obj->vary_headers = xstrdup(r->vary_headers); safe_free(http->entry->mem_obj->vary_encoding); if (strBuf(r->vary_encoding)) - http->entry->mem_obj->vary_encoding = xstrdup(strBuf(r->vary_encoding)); + http->entry->mem_obj->vary_encoding = strCDup(r->vary_encoding); http->entry->mem_obj->request = requestLink(r); EBIT_SET(http->entry->flags, KEY_EARLY_PUBLIC); storeSetPublicKey(http->entry); Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.44.4.2.4.1 retrieving revision 1.44.4.2.4.2 diff -u -r1.44.4.2.4.1 -r1.44.4.2.4.2 --- squid/src/ftp.c 4 Dec 2007 21:56:05 -0000 1.44.4.2.4.1 +++ squid/src/ftp.c 10 Dec 2007 08:56:52 -0000 1.44.4.2.4.2 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.44.4.2.4.1 2007/12/04 21:56:05 adri Exp $ + * $Id: ftp.c,v 1.44.4.2.4.2 2007/12/10 08:56:52 adri Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1527,7 +1527,7 @@ char *d, *p; debug(9, 3) ("This is ftpReadType\n"); if (code == 200) { - p = path = xstrdup(strBuf(ftpState->request->urlpath)); + p = path = strCDup(ftpState->request->urlpath); if (*p == '/') p++; while (*p) { @@ -2372,7 +2372,7 @@ wordlistDestroy(&ftpState->pathcomps); safe_free(ftpState->filepath); /* Build the new path (urlpath begins with /) */ - path = xstrdup(strBuf(ftpState->request->urlpath)); + path = strCDup(ftpState->request->urlpath); rfc1738_unescape(path); ftpState->filepath = path; /* And off we go */ Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.63.2.3 retrieving revision 1.63.2.3.4.1 diff -u -r1.63.2.3 -r1.63.2.3.4.1 --- squid/src/http.c 30 Nov 2007 16:37:01 -0000 1.63.2.3 +++ squid/src/http.c 10 Dec 2007 08:56:54 -0000 1.63.2.3.4.1 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.63.2.3 2007/11/30 16:37:01 adri Exp $ + * $Id: http.c,v 1.63.2.3.4.1 2007/12/10 08:56:54 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -402,8 +402,8 @@ safe_free(request->vary_hdr); safe_free(request->vary_headers); if (strBuf(vary) && strBuf(vstr)) { - request->vary_hdr = xstrdup(strBuf(vary)); - request->vary_headers = xstrdup(strBuf(vstr)); + request->vary_hdr = strCDup(vary); + request->vary_headers = strCDup(vstr); } debug(11, 3) ("httpMakeVaryMark: %s\n", strBuf(vstr)); stringClean(&vary); @@ -530,7 +530,7 @@ } entry->mem_obj->vary_headers = xstrdup(vary); if (strBuf(httpState->orig_request->vary_encoding)) - entry->mem_obj->vary_encoding = xstrdup(strBuf(httpState->orig_request->vary_encoding)); + entry->mem_obj->vary_encoding = strCDup(httpState->orig_request->vary_encoding); } if (entry->mem_obj->old_entry) EBIT_CLR(entry->mem_obj->old_entry->flags, REFRESH_FAILURE); Index: squid/src/squid.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/squid.h,v retrieving revision 1.36.24.6 retrieving revision 1.36.24.7 diff -u -r1.36.24.6 -r1.36.24.7 --- squid/src/squid.h 6 Dec 2007 08:10:27 -0000 1.36.24.6 +++ squid/src/squid.h 10 Dec 2007 08:56:54 -0000 1.36.24.7 @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.36.24.6 2007/12/06 08:10:27 adri Exp $ + * $Id: squid.h,v 1.36.24.7 2007/12/10 08:56:54 adri Exp $ * * AUTHOR: Duane Wessels * @@ -369,6 +369,8 @@ #include "ssl_support.h" #endif +#include "util.h" + /* libcore */ #include "../libcore/tools.h" #include "../libcore/debug.h" @@ -376,7 +378,6 @@ #include "../libcore/syslog.h" #include "../libcore/valgrind.h" - /* libbuf */ #include "../libbuf/buf.h" #include "../libbuf/String.h" @@ -388,7 +389,6 @@ #include "../libmem/memstr.h" #include "../libmem/mem.h" - /* Needed for poll() on Linux at least */ #if USE_POLL #ifndef POLLRDNORM @@ -413,7 +413,6 @@ #include "protos.h" #include "globals.h" -#include "util.h" #if !HAVE_TEMPNAM #include "tempnam.h" Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.49.4.3 retrieving revision 1.49.4.3.4.1 diff -u -r1.49.4.3 -r1.49.4.3.4.1 --- squid/src/store.c 30 Nov 2007 15:55:21 -0000 1.49.4.3 +++ squid/src/store.c 10 Dec 2007 08:56:54 -0000 1.49.4.3.4.1 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.49.4.3 2007/11/30 15:55:21 adri Exp $ + * $Id: store.c,v 1.49.4.3.4.1 2007/12/10 08:56:54 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -974,7 +974,7 @@ state = cbdataAlloc(LocateVaryState); state->vary_data = xstrdup(vary_data); if (strBuf(accept_encoding)) - state->accept_encoding = xstrdup(strBuf(accept_encoding)); + state->accept_encoding = strCDup(accept_encoding); state->data = memPoolAlloc(VaryData_pool); state->e = e; storeLockObject(state->e); Index: squid/src/store_update.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_update.c,v retrieving revision 1.2.4.3 retrieving revision 1.2.4.3.4.1 diff -u -r1.2.4.3 -r1.2.4.3.4.1 --- squid/src/store_update.c 30 Nov 2007 04:16:51 -0000 1.2.4.3 +++ squid/src/store_update.c 10 Dec 2007 08:56:54 -0000 1.2.4.3.4.1 @@ -1,6 +1,6 @@ /* - * $Id: store_update.c,v 1.2.4.3 2007/11/30 04:16:51 adri Exp $ + * $Id: store_update.c,v 1.2.4.3.4.1 2007/12/10 08:56:54 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Henrik Nordstrom @@ -169,7 +169,7 @@ if (vary) { state->newentry->mem_obj->vary_headers = xstrdup(vary); if (strBuf(request->vary_encoding)) - entry->mem_obj->vary_encoding = xstrdup(strBuf(request->vary_encoding)); + entry->mem_obj->vary_encoding = strCDup(request->vary_encoding); } } else { if (entry->mem_obj->vary_headers) Index: squid/src/urn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/urn.c,v retrieving revision 1.24.6.2.4.1 retrieving revision 1.24.6.2.4.2 diff -u -r1.24.6.2.4.1 -r1.24.6.2.4.2 --- squid/src/urn.c 4 Dec 2007 21:56:06 -0000 1.24.6.2.4.1 +++ squid/src/urn.c 10 Dec 2007 08:56:54 -0000 1.24.6.2.4.2 @@ -1,6 +1,6 @@ /* - * $Id: urn.c,v 1.24.6.2.4.1 2007/12/04 21:56:06 adri Exp $ + * $Id: urn.c,v 1.24.6.2.4.2 2007/12/10 08:56:54 adri Exp $ * * DEBUG: section 52 URN Parsing * AUTHOR: Kostas Anagnostakis @@ -113,7 +113,7 @@ urnState->request = requestLink(r); storeLockObject(urnState->entry); if (strncasecmp(strBuf(r->urlpath), "menu.", 5) == 0) { - char *new_path = xstrdup(strBuf(r->urlpath) + 5); + char *new_path = strCDupOffset(r->urlpath, 5); urnState->flags.force_menu = 1; stringReset(&r->urlpath, new_path); xfree(new_path); @@ -121,10 +121,10 @@ if ((s = strChr(r->urlpath, ':')) != -1) { /* XXX this doesn't update the length; perhaps strCut() is better? */ strSet(r->urlpath, s, '\0'); - host = xstrdup(strBuf(r->urlpath)); + host = strCDup(r->urlpath); strSet(r->urlpath, s, ':'); } else { - host = xstrdup(strBuf(r->urlpath)); + host = strCDup(r->urlpath); } snprintf(urlres, 4096, "http://%s/uri-res/N2L?urn:%s", host, strBuf(r->urlpath)); safe_free(host);