From a452d3a9f526f6545981664712b45f709545e6fa Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 26 Mar 2025 15:42:57 +0100 Subject: Respect custom LESS/MORE/LV variables Use setenv() to avoid overriding user defined variables. LP: #2103921 --- apt-private/private-output.cc | 12 +++++++++++- test/integration/test-apt-cli-pager | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 4480d7382..a1105be61 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -160,7 +160,17 @@ bool InitOutputPager() signal(sig, SIG_DFL); for (auto &v: pagerEnv) - putenv(v.data()); + { + // WARNING: VectorizeString() is not thread-safe, do not call after creating a thread. + auto keyAndValue = VectorizeString(v, '='); + if (keyAndValue.size() != 2) + { + _error->Fatal("Invalid environment string: %s", v.c_str()); + goto err; + } + // NOTE: Must not override user values, so setenv(..., override=0) is used rather than putenv() + setenv(keyAndValue[0].c_str(), keyAndValue[1].c_str(), 0); + } { // If our pager name contains a space we need to invoke it in a shell. Boooo! diff --git a/test/integration/test-apt-cli-pager b/test/integration/test-apt-cli-pager index d1f8c3288..cc220c81f 100755 --- a/test/integration/test-apt-cli-pager +++ b/test/integration/test-apt-cli-pager @@ -125,3 +125,6 @@ Checksums-Sha256: PAGER="head -2" testsuccessequal "Package: foo Binary: foo" runapt --unbuffer apt showsrc foo -o TestPager="head- 2" + +PAGER='echo $LESS' testsuccessequal "FRX" runapt --unbuffer apt showsrc foo -o TestPager='echo $LESS (1)' +LESS=FRXM PAGER='echo $LESS' testsuccessequal "FRXM" runapt --unbuffer apt showsrc foo -o TestPager='echo $LESS (2)' -- cgit v1.2.3-70-g09d2