From owner-freebsd-current@FreeBSD.ORG Thu Jul 1 13:47:19 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C1513106566B for ; Thu, 1 Jul 2010 13:47:19 +0000 (UTC) (envelope-from tevans.uk@googlemail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 4E7318FC24 for ; Thu, 1 Jul 2010 13:47:18 +0000 (UTC) Received: by wwb28 with SMTP id 28so829938wwb.31 for ; Thu, 01 Jul 2010 06:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=8i4JROr7eWXGiHqoSQDp2wL7BbRFmsUfFCitlTZrFX8=; b=HiHdTZv8bjM/N4ITXgkQiV0X0k6S4gb2qhdzdK15pOE15qhcd0NyrUht5+pn0PL6Oz TIAnSNk27RJwmXxr/b1yf52Ao5PSVjTb69qyNKcUeG1JYg1eVEGMEtjGNZnNrmidw46z HHTCDr+NGfBPGsM/ZtEnmPH9WRz1ST1fjJ6co= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=x8GrlclQa3L9Bd+0Gw/IkgRlMQMS79y2t3PtQyl2+B7tPvQocy/cRfsuPhmSi8eiEp nCu/jHhLSgnT4/HwGwxbv49RLmXf6aOUO7IXANQu0oQNK1QWcDUDA6TZlGVawHKgxosf RbDlQMwo27qyaVJygebcdreRpFolvY5qe8I/g= MIME-Version: 1.0 Received: by 10.213.28.68 with SMTP id l4mr5466869ebc.12.1277992030372; Thu, 01 Jul 2010 06:47:10 -0700 (PDT) Received: by 10.213.15.208 with HTTP; Thu, 1 Jul 2010 06:47:10 -0700 (PDT) In-Reply-To: <86pqz8mkcg.fsf@ds4.des.no> References: <20100621101046.GA76036@droso.net> <20100621130743.4df77343@ernst.jennejohn.org> <86pqz8mkcg.fsf@ds4.des.no> Date: Thu, 1 Jul 2010 14:47:10 +0100 Message-ID: From: Tom Evans To: =?UTF-8?Q?Dag=2DErling_Sm=C3=B8rgrav?= Content-Type: multipart/mixed; boundary=0015174c3774ff07fa048a53b4fb Cc: freebsd-current Subject: Re: Ports doesnt respect fetch environment settings X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2010 13:47:19 -0000 --0015174c3774ff07fa048a53b4fb Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2010/6/30 Dag-Erling Sm=C3=B8rgrav : > Tom Evans writes: >> Sorry to bump this again. I've diluted this issue down to the core >> points and raised as a pr - can someone take a look, see if my >> solution is correct and commit if appropriate? > > Sorry, fell through the cracks. =C2=A0Your analysis is correct, but I'm n= ot > 100% sure about the patch. =C2=A0Can you verify that your change does not > introduce the possibility of an infinite loop in edge cases? =C2=A0I don'= t > *think* it does, but like I said, I'm not 100% sure and I don't have > time to reacquaint myself with the code right now, especially not that > particularly nasty part of it :) > > DES > -- > Dag-Erling Sm=C3=B8rgrav - des@des.no > Like you said, it's quite a large chunk of code to understand. I think you might be right, there could be a situation where a misbehaving proxy server could make it loop. The process is like this: http_auth_challenges_t proxy_challenges struct initialized (line 1497). The flag 'valid' on the struct is initialized to 0 (line 656) We enter the loop for the first time. We dont add proxy auth the first time through the loop, as 'valid' flag not set (line 1586) We receive the reply and switch on the response code (line 1676) If we receive HTTP_NEED_PROXY_AUTH, and the 'valid' flag is not set (implying we didn't send creds), we simply continue to execute the loop (lines 1703 - 1716). This is where the patch I supplied increments the maximum loop counter. The loop now processes the received headers, and when it receives the 'Proxy-Authenticate' header, it calls http_parse_authenticate with proxy_challenges (line 1795) This then populates the proxy_challenges struct, setting the valid flag. Having processed the headers, the loop then checks that receiving a HTTP_NEED_PROXY_AUTH response has resulted in us now having valid flag set in proxy_challenges, otherwise we goto ouch (out of the loop) (line 1806). The loop ends, and we go through again. I thought for a moment while tracing it through that if a misbehaving proxy server sent a 407 response, but did not add a Proxy-Authenticate header, then we could increase the loop counter but without adding any proxy auth, which would mean an infinite loop. However, there is already that sanity check at the end of the loop to check that if we received a proxy authentication error, and still dont have credentials to supply, then we quickly jump out of the loop. I guess that is a little strange, that we could supply proxy auth credentials, but because the server didnt ask for them correctly, we didnt give them - although that would be quite broken behaviour on the part of the proxy server. I think this does show that the patch could be made a little better. We only want to go through the loop one more time if we have credentials to send, and we have credentials to send if the rv of http_parse_authenticate is good. I also think the same bug would affect fetching from servers requiring authentication, so I've made the same fix there as well. New patch attached Cheers Tom --0015174c3774ff07fa048a53b4fb Content-Type: text/plain; charset=US-ASCII; name="lib::libfetch::http.c.diff.txt" Content-Disposition: attachment; filename="lib::libfetch::http.c.diff.txt" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gb3nfay00 SW5kZXg6IGh0dHAuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvaG9tZS9uY3ZzL3NyYy9saWIvbGli ZmV0Y2gvaHR0cC5jLHYKcmV0cmlldmluZyByZXZpc2lvbiAxLjc4LjIuNQpkaWZmIC11IC1yMS43 OC4yLjUgaHR0cC5jCi0tLSBodHRwLmMJMjcgSmFuIDIwMTAgMTQ6NTQ6NDggLTAwMDAJMS43OC4y LjUKKysrIGh0dHAuYwkxIEp1bCAyMDEwIDEzOjQ1OjA2IC0wMDAwCkBAIC0xNzg2LDEyICsxNzg2 LDE0IEBACiAJCQljYXNlIGhkcl93d3dfYXV0aGVudGljYXRlOgogCQkJCWlmIChjb25uLT5lcnIg IT0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