[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#620344: apt: http method sends bogus Host: header



Control: tags -1 + patch

Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
>  configured a http source line using an ipv6 IP
>
> 	deb http://[2345:abcd::1]/debian/ squeeze main contrib non-free
>
> and this results in
>
> 	Err http://[2345:abcd::1] squeeze/main amd64 Packages 
> 	  400  Bad Request
>
> because the Host: header in the http request is bogus, it sends
>
> 	Host: 2345:abcd::1
>
> instead of
>
> 	Host: [2345:abcd::1]

Right.  See attached.

I'm not sure why URI::operator string also checks for '/' in host,
because thats not part of any IP-literal syntax.  Maybe it's important
to add in this patch also, then there should probably be a separate
HostToStr method in strutl to handle it.

=== modified file 'methods/http.cc'
--- methods/http.cc	2013-01-24 17:52:25 +0000
+++ methods/http.cc	2013-03-02 14:47:10 +0000
@@ -668,6 +668,11 @@
    // The HTTP server expects a hostname with a trailing :port
    char Buf[1000];
    string ProperHost = Uri.Host;
+   if (ProperHost.find(':') != string::npos)
+   {
+      // Host is an IP-literal.
+      ProperHost = '[' + ProperHost + ']';
+   }
    if (Uri.Port != 0)
    {
       sprintf(Buf,":%u",Uri.Port);


Reply to: