Commit 2040b8a9 authored by Geoff Simmons's avatar Geoff Simmons

bugfix determining that a URL encoding is illegal

parent 30a16b53
...@@ -214,32 +214,45 @@ client c1 { ...@@ -214,32 +214,45 @@ client c1 {
expect resp.http.decmanypieces == "foo bar baz quux" expect resp.http.decmanypieces == "foo bar baz quux"
} -run } -run
#varnish v1 -vcl { varnish v1 -vcl {
# import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so"; import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
# backend b { .host = "${bad_ip}"; } backend b { .host = "${bad_ip}"; }
#
# sub vcl_recv { sub vcl_recv {
# return(synth(200)); return(synth(200));
# } }
#
# sub vcl_synth { sub vcl_synth {
# set req.http.foo = "123"; set resp.http.bad1 = blobcode.encode(URLUC, blobcode.decode(URL, "%"));
# set resp.http.badurl = blobcode.encode(URLUC, set resp.http.bad2 = blobcode.encode(URLUC,
# blobcode.decode(URL, "g" + req.http.foo)); blobcode.decode(URL, "%2"));
# } set resp.http.bad3 = blobcode.encode(URLUC,
#} blobcode.decode(URL, "%q"));
set resp.http.bad4 = blobcode.encode(URLUC,
#client c1 { blobcode.decode(URL, "%2q"));
# txreq }
# rxresp }
# expect resp.http.badurl == ""
#} -run client c1 {
txreq
#logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" { rxresp
# expect 0 * Begin req expect resp.http.bad1 == ""
# expect * = VCL_Error "^vmod blobcode error: cannot decode, illegal encoding beginning with \"g\"$" expect resp.http.bad2 == ""
expect resp.http.bad3 == ""
expect resp.http.bad4 == ""
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod blobcode error: cannot decode, illegal encoding beginning with \"%\"$"
#" #"
# expect * = End expect * = VCL_Error "^vmod blobcode error: cannot decode, illegal encoding beginning with \"%2\"$"
#} -start #"
expect * = VCL_Error "^vmod blobcode error: cannot decode, illegal encoding beginning with \"%q\"$"
#"
expect * = VCL_Error "^vmod blobcode error: cannot decode, illegal encoding beginning with \"%2q\"$"
#"
expect * = End
} -start
#logexpect l1 -wait logexpect l1 -wait
...@@ -94,6 +94,12 @@ isunreserved(const uint8_t c) ...@@ -94,6 +94,12 @@ isunreserved(const uint8_t c)
return (unreserved[c >> 3] & (1 << (c & 7))); return (unreserved[c >> 3] & (1 << (c & 7)));
} }
static inline int
isoutofrange(const uint8_t c)
{
return (c < '0' || c > 'f');
}
ssize_t ssize_t
url_encode(const enum encoding enc, char *restrict const buf, url_encode(const enum encoding enc, char *restrict const buf,
const size_t buflen, const char *restrict const in, const size_t buflen, const char *restrict const in,
...@@ -164,14 +170,16 @@ url_decode(const enum encoding dec, char *restrict const buf, ...@@ -164,14 +170,16 @@ url_decode(const enum encoding dec, char *restrict const buf,
*dest++ = *s; *dest++ = *s;
break; break;
case PERCENT: case PERCENT:
if ((nib = nibble[*s - '0']) == 0xff) { if (isoutofrange(*s)
|| (nib = nibble[*s - '0']) == 0xff) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
state = FIRSTNIB; state = FIRSTNIB;
break; break;
case FIRSTNIB: case FIRSTNIB:
if ((nib2 = nibble[*s - '0']) == 0xff) { if (isoutofrange(*s)
|| (nib2 = nibble[*s - '0']) == 0xff) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment