File curl-CVE-2013-1944.patch of Package curl.1590
Index: curl-7.22.0/lib/cookie.c
===================================================================
--- curl-7.22.0.orig/lib/cookie.c 2013-04-15 16:30:53.578606674 +0200
+++ curl-7.22.0/lib/cookie.c 2013-04-15 16:30:54.799644388 +0200
@@ -118,15 +118,29 @@ static void freecookie(struct Cookie *co
free(co);
}
-static bool tailmatch(const char *little, const char *bigone)
+static bool tailmatch(const char *cooke_domain, const char *hostname)
{
- size_t littlelen = strlen(little);
- size_t biglen = strlen(bigone);
+ size_t cookie_domain_len = strlen(cooke_domain);
+ size_t hostname_len = strlen(hostname);
- if(littlelen > biglen)
+ if(hostname_len < cookie_domain_len)
return FALSE;
- return Curl_raw_equal(little, bigone+biglen-littlelen) ? TRUE : FALSE;
+ if(!Curl_raw_equal(cooke_domain, hostname+hostname_len-cookie_domain_len))
+ return FALSE;
+
+ /* A lead char of cookie_domain is not '.'.
+ RFC6265 4.1.2.3. The Domain Attribute says:
+ For example, if the value of the Domain attribute is
+ "example.com", the user agent will include the cookie in the Cookie
+ header when making HTTP requests to example.com, www.example.com, and
+ www.corp.example.com.
+ */
+ if(hostname_len == cookie_domain_len)
+ return TRUE;
+ if('.' == *(hostname + hostname_len - cookie_domain_len - 1))
+ return TRUE;
+ return FALSE;
}
/*
Index: curl-7.22.0/tests/data/Makefile.am
===================================================================
--- curl-7.22.0.orig/tests/data/Makefile.am 2013-04-15 16:30:54.800644419 +0200
+++ curl-7.22.0/tests/data/Makefile.am 2013-04-15 16:32:06.222850373 +0200
@@ -74,6 +74,7 @@ test1110 test1111 test1112 test1113 test
test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125 \
test1126 test1127 test1128 test1129 test1130 test1131 test1200 test1201 \
test1202 test1203 test1300 test1301 test1302 test1303 test1304 test1305 \
+test1218 \
test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
test2000 test2001 test2002 test2003 test2004
Index: curl-7.22.0/tests/data/test1218
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ curl-7.22.0/tests/data/test1218 2013-04-15 16:30:54.800644419 +0200
@@ -0,0 +1,61 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+HTTP proxy
+cookies
+</keywords>
+</info>
+
+# This test is very similar to 1216, only that it sets the cookies from the
+# first site instead of reading from a file
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Tue, 25 Sep 2001 19:37:44 GMT
+Set-Cookie: domain=.example.fake; bug=fixed;
+Content-Length: 21
+
+This server says moo
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP cookies and domains with same prefix
+ </name>
+ <command>
+http://example.fake/c/1218 http://example.fake/c/1218 http://bexample.fake/c/1218 -b nonexisting -x %HOSTIP:%HTTPPORT
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET http://example.fake/c/1218 HTTP/1.1
+Host: example.fake
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+GET http://example.fake/c/1218 HTTP/1.1
+Host: example.fake
+Accept: */*
+Proxy-Connection: Keep-Alive
+Cookie: bug=fixed
+
+GET http://bexample.fake/c/1218 HTTP/1.1
+Host: bexample.fake
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+</protocol>
+</verify>
+</testcase>