--------------------- PatchSet 10258 Date: 2007/12/16 14:25:57 Author: adri Branch: s27_adri Tag: (none) Log: Remove strBuf() calls in parsing some header values. This creates a couple of *Str() routines to parse Int and Size; this uses a temporary buffer to NUL terminate the data before parsing. This is a temporary measure (and documented as such!) which should be fixed later by introducing a length-aware strtoll() implementation. Members: ADRIAN_TODO:1.1.2.9->1.1.2.10 src/HttpHeader.c:1.28.6.1.4.17->1.28.6.1.4.18 src/HttpHeaderTools.c:1.14.10.2->1.14.10.3 src/protos.h:1.146.2.4.4.20->1.146.2.4.4.21 Index: squid/ADRIAN_TODO =================================================================== RCS file: /cvsroot/squid-sf//squid/Attic/ADRIAN_TODO,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- squid/ADRIAN_TODO 16 Dec 2007 13:17:44 -0000 1.1.2.9 +++ squid/ADRIAN_TODO 16 Dec 2007 14:25:57 -0000 1.1.2.10 @@ -59,3 +59,7 @@ * convert storeUrl() and similar to return String or a String reference! +* httpHeaderParseSizeStr and httpHeaderParseIntStr both use temporary buffers + that are NUL-terminated; please write replacement strotoll() which takes a len + parameter; this will avoid the temporary copy which is being done now. + Index: squid/src/HttpHeader.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHeader.c,v retrieving revision 1.28.6.1.4.17 retrieving revision 1.28.6.1.4.18 diff -u -r1.28.6.1.4.17 -r1.28.6.1.4.18 --- squid/src/HttpHeader.c 15 Dec 2007 11:17:04 -0000 1.28.6.1.4.17 +++ squid/src/HttpHeader.c 16 Dec 2007 14:25:57 -0000 1.28.6.1.4.18 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.28.6.1.4.17 2007/12/15 11:17:04 adri Exp $ + * $Id: HttpHeader.c,v 1.28.6.1.4.18 2007/12/16 14:25:57 adri Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -521,7 +521,7 @@ if (e->id == HDR_CONTENT_LENGTH) { squid_off_t l1; HttpHeaderEntry *e2; - if (!httpHeaderParseSize(strBuf(e->value), &l1)) { + if (!httpHeaderParseSizeStr(e->value, &l1)) { debug(55, 1) ("WARNING: Unparseable content-length '%.*s'\n", strLen2(e->value), strBuf2(e->value)); httpHeaderEntryDestroy(e); return httpHeaderReset(hdr); @@ -534,7 +534,7 @@ httpHeaderEntryDestroy(e); return httpHeaderReset(hdr); } - if (!httpHeaderParseSize(strBuf(e2->value), &l2)) { + if (!httpHeaderParseSizeStr(e2->value, &l2)) { debug(55, 1) ("WARNING: Unparseable content-length '%.*s'\n", strLen2(e->value), strBuf2(e->value)); httpHeaderEntryDestroy(e); return httpHeaderReset(hdr); @@ -1065,7 +1065,7 @@ assert_eid(id); assert(Headers[id].type == ftInt); /* must be of an appropriate type */ if ((e = httpHeaderFindEntry(hdr, id))) { - ok = httpHeaderParseInt(strBuf(e->value), &value); + ok = httpHeaderParseIntStr(e->value, &value); httpHeaderNoteParsedEntry(e->id, e->value, !ok); } return value; @@ -1080,7 +1080,7 @@ assert_eid(id); assert(Headers[id].type == ftSize); /* must be of an appropriate type */ if ((e = httpHeaderFindEntry(hdr, id))) { - ok = httpHeaderParseSize(strBuf(e->value), &value); + ok = httpHeaderParseSizeStr(e->value, &value); httpHeaderNoteParsedEntry(e->id, e->value, !ok); } return value; Index: squid/src/HttpHeaderTools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHeaderTools.c,v retrieving revision 1.14.10.2 retrieving revision 1.14.10.3 diff -u -r1.14.10.2 -r1.14.10.3 --- squid/src/HttpHeaderTools.c 13 Dec 2007 13:10:33 -0000 1.14.10.2 +++ squid/src/HttpHeaderTools.c 16 Dec 2007 14:25:57 -0000 1.14.10.3 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeaderTools.c,v 1.14.10.2 2007/12/13 13:10:33 adri Exp $ + * $Id: HttpHeaderTools.c,v 1.14.10.3 2007/12/16 14:25:57 adri Exp $ * * DEBUG: section 66 HTTP Header Tools * AUTHOR: Alex Rousskov @@ -299,6 +299,21 @@ return buf; } +int +httpHeaderParseIntStr(String s, int *value) +{ + char buf[128]; /* XXX make sure its enough to parse a number that won't overflow! */ + /* + * XXX a temporary buffer is used for now so strto_off_t, which uses + * XXX strtoll, can do its thing. Later on this should be modified + * XXX to use a length-aware routine rather than a NUL-terminated string + * XXX parsing routine. + */ + xmemcpy(buf, strBuf2(s), XMIN(127, strLen2(s))); + buf[XMIN(127, strLen2(s))] = '\0'; /* XXX just in case */ + return httpHeaderParseInt(buf, value); +} + /* * parses an int field, complains if soemthing went wrong, returns true on * success @@ -320,6 +335,21 @@ } int +httpHeaderParseSizeStr(String s, squid_off_t * value) +{ + char buf[128]; /* XXX make sure its enough to parse a number that won't overflow! */ + /* + * XXX a temporary buffer is used for now so strto_off_t, which uses + * XXX strtoll, can do its thing. Later on this should be modified + * XXX to use a length-aware routine rather than a NUL-terminated string + * XXX parsing routine. + */ + xmemcpy(buf, strBuf2(s), XMIN(127, strLen2(s))); + buf[XMIN(127, strLen2(s))] = '\0'; /* XXX just in case */ + return httpHeaderParseSize(buf, value); +} + +int httpHeaderParseSize(const char *start, squid_off_t * value) { char *end; Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.146.2.4.4.20 retrieving revision 1.146.2.4.4.21 diff -u -r1.146.2.4.4.20 -r1.146.2.4.4.21 --- squid/src/protos.h 16 Dec 2007 02:32:26 -0000 1.146.2.4.4.20 +++ squid/src/protos.h 16 Dec 2007 14:25:57 -0000 1.146.2.4.4.21 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.146.2.4.4.20 2007/12/16 02:32:26 adri Exp $ + * $Id: protos.h,v 1.146.2.4.4.21 2007/12/16 14:25:57 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -401,7 +401,9 @@ extern int strListGetItem(const String * str, char del, const char **item, int *ilen, const char **pos); extern const char *getStringPrefix(const char *str, const char *end); extern int httpHeaderParseInt(const char *start, int *val); +extern int httpHeaderParseIntStr(String s, int *val); extern int httpHeaderParseSize(const char *start, squid_off_t * sz); +extern int httpHeaderParseSizeStr(String s, squid_off_t * value); extern int httpHeaderReset(HttpHeader * hdr); extern void httpHeaderAddClone(HttpHeader * hdr, const HttpHeaderEntry * e); #if STDC_HEADERS