Author: joes Date: Thu Apr 28 13:01:02 2005 New Revision: 165189 URL: http://svn.apache.org/viewcvs?rev=165189&view=rev Log: Apply Max Kellermann's "[PATCN] apreq_quote() fixes and more":
http://marc.theaimsgroup.com/?l=apreq-dev&m=111471098727811&w=2 Submitted by: Max Kellermann Reviewed by: joes Modified: httpd/apreq/trunk/CHANGES httpd/apreq/trunk/acinclude.m4 httpd/apreq/trunk/library/module_custom.c httpd/apreq/trunk/library/t/util.c httpd/apreq/trunk/library/util.c Modified: httpd/apreq/trunk/CHANGES URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/CHANGES?rev=165189&r1=165188&r2=165189&view=diff ============================================================================== --- httpd/apreq/trunk/CHANGES (original) +++ httpd/apreq/trunk/CHANGES Thu Apr 28 13:01:02 2005 @@ -5,6 +5,9 @@ @section v2_05_dev Changes with libapreq2-2.05-dev +- C API [Max Kellermann] + Fix apreq_quote. + - Perl API [joes] Remove Apache2::Request::args. WARNING: through inheritance, args() now maps to Apache2::RequestRec::args. Folks that want Modified: httpd/apreq/trunk/acinclude.m4 URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/acinclude.m4?rev=165189&r1=165188&r2=165189&view=diff ============================================================================== --- httpd/apreq/trunk/acinclude.m4 (original) +++ httpd/apreq/trunk/acinclude.m4 Thu Apr 28 13:01:02 2005 @@ -188,7 +188,7 @@ APR_ADDTO([CPPFLAGS], "`$APR_CONFIG --cppflags`") - get_version="$abs_srcdir/build/get-version.sh" + get_version="$SHELL $abs_srcdir/build/get-version.sh" version_hdr="$abs_srcdir/include/apreq_version.h" # set version data Modified: httpd/apreq/trunk/library/module_custom.c URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/library/module_custom.c?rev=165189&r1=165188&r2=165189&view=diff ============================================================================== --- httpd/apreq/trunk/library/module_custom.c (original) +++ httpd/apreq/trunk/library/module_custom.c Thu Apr 28 13:01:02 2005 @@ -49,7 +49,7 @@ return req->body_status; switch (s = apr_brigade_partition(req->in, bytes, &e)) { - apr_uint64_t len; + apr_off_t len; case APR_SUCCESS: apreq_brigade_move(req->tmpbb, req->in, e); Modified: httpd/apreq/trunk/library/t/util.c URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/library/t/util.c?rev=165189&r1=165188&r2=165189&view=diff ============================================================================== --- httpd/apreq/trunk/library/t/util.c (original) +++ httpd/apreq/trunk/library/t/util.c Thu Apr 28 13:01:02 2005 @@ -162,12 +162,62 @@ static void test_quote(dAT) { + size_t len; + char dst[64]; + len = apreq_quote(dst, "foo", 3); + AT_int_eq(len, 5); + AT_str_eq(dst, "\"foo\""); + + len = apreq_quote(dst, "\"foo", 4); + AT_int_eq(len, 7); + AT_str_eq(dst, "\"\\\"foo\""); + + len = apreq_quote(dst, "foo\0bar", 7); + AT_int_eq(len, 9); + AT_mem_eq(dst, "\"foo\0bar\"", len + 1); } static void test_quote_once(dAT) { + size_t len; + char dst[64]; + len = apreq_quote_once(dst, "foo", 3); + AT_int_eq(len, 5); + AT_str_eq(dst, "\"foo\""); + + len = apreq_quote_once(dst, "\"foo", 4); + AT_int_eq(len, 7); + AT_str_eq(dst, "\"\\\"foo\""); + + len = apreq_quote_once(dst, "foo\"", 4); + AT_int_eq(len, 7); + AT_str_eq(dst, "\"foo\\\"\""); + + len = apreq_quote_once(dst, "foo\0bar", 7); + AT_int_eq(len, 9); + AT_mem_eq(dst, "\"foo\0bar\"", len + 1); + + len = apreq_quote_once(dst, "\"foo\0bar\"", 9); + AT_int_eq(len, 9); + AT_mem_eq(dst, "\"foo\0bar\"", len + 1); + + len = apreq_quote_once(dst, "\"foo\"", 5); + AT_int_eq(len, 5); + AT_str_eq(dst, "\"foo\""); + + len = apreq_quote_once(dst, "'foo'", 5); + AT_int_eq(len, 7); + AT_str_eq(dst, "\"'foo'\""); + + len = apreq_quote_once(dst, "\"foo\"", 5); + AT_int_eq(len, 5); + AT_str_eq(dst, "\"foo\""); + + len = apreq_quote_once(dst, "\"foo\"bar\"", 9); + AT_int_eq(len, 14); + AT_str_eq(dst, "\"\\\"foo\\\"bar\\\"\""); } static void test_join(dAT) @@ -215,8 +265,8 @@ { dT(test_decodev, 6) }, { dT(test_encode, 0) }, { dT(test_cp1252_to_utf8, 14) }, - { dT(test_quote, 0) }, - { dT(test_quote_once, 0), }, + { dT(test_quote, 6) }, + { dT(test_quote_once, 18), }, { dT(test_join, 0) }, { dT(test_brigade_fwrite, 0) }, { dT(test_file_mktemp, 0) }, Modified: httpd/apreq/trunk/library/util.c URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/library/util.c?rev=165189&r1=165188&r2=165189&view=diff ============================================================================== --- httpd/apreq/trunk/library/util.c (original) +++ httpd/apreq/trunk/library/util.c Thu Apr 28 13:01:02 2005 @@ -668,12 +668,33 @@ return d - dest; } +static int is_quoted(const char *p, const apr_size_t len) { + if (len > 1 && p[0] == '"' && p[len-1] == '"') { + apr_size_t i; + int backslash = 0; + + for (i = 1; i < len - 1; i++) { + if (p[i] == '\\') + backslash = !backslash; + else if (p[i] == '"' && !backslash) + return 0; + else + backslash = 0; + } + + return !backslash; + } + + return 0; +} + APREQ_DECLARE(apr_size_t) apreq_quote_once(char *dest, const char *src, const apr_size_t slen) { - if (slen > 1 && src[0] == '"' && src[slen-1] == '"') { + if (is_quoted(src, slen)) { /* looks like src is already quoted */ memcpy(dest, src, slen); + dest[slen] = 0; return slen; } else @@ -747,7 +768,8 @@ case APREQ_JOIN_QUOTE: len = 2 * (len + n); break; - default: + case APREQ_JOIN_AS_IS: + case APREQ_JOIN_DECODE: /* nothing special required, just here to keep noisy compilers happy */ break; } @@ -809,9 +831,6 @@ memcpy(d, a[j]->data, a[j]->dlen); d += a[j]->dlen; } - break; - - default: break; }
