From 78046276db89bed39cde785760cd5d0c694ddb1d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 2 Oct 2016 17:20:33 +0200 Subject: Do not read stderr from proxy autodetection scripts This fixes a regression introduced in commit 8f858d560e3b7b475c623c4e242d1edce246025a don't leak FD in AutoProxyDetect command return parsing which accidentally made the proxy autodetection code also read the scripts output on stderr, not only on stdout when it switched the code from popen() to Popen(). Reported-By: Tim Small (cherry picked from commit 0ecceb5bb9cc8727c117195945b7116aceb984fe) --- test/libapt/apt-proxy-script | 9 +++++++++ test/libapt/uri_test.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 test/libapt/apt-proxy-script (limited to 'test/libapt') diff --git a/test/libapt/apt-proxy-script b/test/libapt/apt-proxy-script new file mode 100755 index 000000000..41cfdc30f --- /dev/null +++ b/test/libapt/apt-proxy-script @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ $1 = "http://www.debian.org:90/temp/test" ]; then + echo "http://example.com" +fi +if [ $1 = "http://www.debian.org:91/temp/test" ]; then + echo "This works" >&2 + echo "http://example.com/foo" +fi diff --git a/test/libapt/uri_test.cc b/test/libapt/uri_test.cc index 8296ca6a0..09d018049 100644 --- a/test/libapt/uri_test.cc +++ b/test/libapt/uri_test.cc @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -188,3 +190,27 @@ TEST(URITest, RFC2732) EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U)); EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U)); } +TEST(URITest, AutoProxyTest) +{ + URI u0("http://www.debian.org:90/temp/test"); + URI u1("http://www.debian.org:91/temp/test"); + + _config->Set("Acquire::http::Proxy-Auto-Detect", "./apt-proxy-script"); + + // Scenario 0: Autodetecting a simple proxy + AutoDetectProxy(u0); + EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com"); + + // Scenario 1: Proxy stays the same if it is already set + AutoDetectProxy(u1); + EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com"); + + // Scenario 2: Reading with stderr output works fine + _config->Clear("Acquire::http::proxy::www.debian.org"); + AutoDetectProxy(u1); + EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com/foo"); + + // Scenario 1 again: Proxy stays the same if it is already set + AutoDetectProxy(u0); + EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com/foo"); +} -- cgit v1.2.3