curl-library
Re: curl gets into infinite redirect loop
Date: Thu, 29 Dec 2011 13:31:56 -0600
ok hacked around a bit in libcurl
Added strtolower function to http.c. Was not sure if libcurl has similar
function. See code diff below. It fixed the problem! curl now gets to the
final destination. Run all tests.
TESTDONE: 563 tests out of 564 reported OK: 99%
TESTFAIL: These test cases failed: 1035 => it is clear why because
expected Host value has uppercase letters.
What you guys think about this change?
$ git diff lib/http.c
diff --git a/lib/http.c b/lib/http.c
index fe1c7fd..4300837 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -104,6 +104,15 @@ static int https_getsock(struct connectdata *conn,
#define https_connecting(x,y) CURLE_COULDNT_CONNECT
#endif
+void strtolower(char str[]) {
+ while(*str != 0) {
+ if (*str >= 'A' && *str <= 'Z') {
+ *str = *str + 'a' - 'A';
+ }
+ str++;
+ }
+}
+
/*
* HTTP handler interface.
*/
@@ -1667,6 +1676,7 @@ CURLcode Curl_http(struct connectdata *conn, bool
*done)
const char *ppath = data->state.path;
bool paste_ftp_userpwd = FALSE;
char ftp_typecode[sizeof("/;type=?")] = "";
+ strtolower(conn->host.name);
const char *host = conn->host.name;
const char *te = ""; /* transfer-encoding */
const char *ptr;
On Thu, Dec 29, 2011 at 9:52 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Wed, 28 Dec 2011, Alex Vinnik wrote:
>
> Unearthed one more interesting redirect case at least for me :) ... curl
>> gets into infinite redirect loop with a website and exists after hitting
>> redirect limit.
>>
>> Here is how to reproduce it. Verbose libcurl output is below
>>
>> curl -ivL http://www.kqzyfj.com/click-0-**10721226<http://www.kqzyfj.com/click-0-10721226>
>>
>> In a nutshell... It is clear that one of the early re-directors provides
>> mixed case Location url http://www.UltraFragrances.**com/<http://www.UltraFragrances.com/>which is not correct.
>>
>
> It might be clear that this is the reason for what is going on. It is not
> clear to me that it is "not correct". (And it might not even be the reason
> for this failure.)
>
> The host name in a URL (URI) is specificly specified to be case
> insensitive. ABC.com is the same as abc.com and AbC.com. Therfore,
> UltraFragrances.com is the same host as ultrafragrances.com and using
> either version in the Host: header should be equivalent.
>
> I would claim that separating them only on the basis of different case in
> the host name would be violating specs.
>
> I'll admit that there's a problem when browsers act differently on a site
> when that different behahavior is what makes things work - and such
> behaviors many times end up pushing us towards doing weirdo stuff even
> though we shouldn't have to.
>
> As usual Chrome just handles it fine by converting first incorrect mixed
>> case Location url to all lower case. Any workaround for this case?
>>
>
> Are you saying Chrome always lowercases host names in the Host: header?
> Did you check how other browsers act in this situation?
>
> Perhaps even more importantly, if you would hack your curl verson to lower
> case the host name in the header, does it truly make this operation work
> against this site? There's actually a risk that the site uses some other
> heuristic to do this weirdness that we just haven't spotted.
>
> --
>
> / daniel.haxx.se
> ------------------------------**------------------------------**-------
> List admin: http://cool.haxx.se/list/**listinfo/curl-library<http://cool.haxx.se/list/listinfo/curl-library>
> Etiquette: http://curl.haxx.se/mail/**etiquette.html<http://curl.haxx.se/mail/etiquette.html>
>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-12-29