Re: [PATCH 29/29] t/test-lib: teach --chain-lint to detect broken &&-chains in subshells
- From
Elijah Newren <newren@gmail.com>
- Date
- Jun 27, 2018, 02:15 UTC
- Message-ID
- <CABPp-BHgPgkgQj7i3rZtdbinVZvqH35uGraUK9doL-E8Y5QuSQ@mail.gmail.com>
- In-Reply-To
- <20180626210100.GA3682@sigill.intra.peff.net>
On Tue, Jun 26, 2018 at 2:01 PM, Jeff King <peff@peff.net> wrote:
> On Tue, Jun 26, 2018 at 04:46:18PM -0400, Eric Sunshine wrote:
Show 14 quoted lines
>> Some of these dangers can be de-thoothed during the linting phase by
>> defining do-nothing shell functions:
>>
>> cp () { :; }
>> mv () { :; }
>> ln () { :; }
>>
>> That, at least, makes the scariest case ("rm") much less so.
>
> Now that's an interesting idea. We can't catch every dangerous action
> (notably ">" would be hard to override), but it should be pretty cheap
> to cover some obvious ones.
>
> -PeffCrazy idea: maybe we could defang it a little more thoroughly with something like the following (apologies in advance if gmail whitespace damages this):
diff --git a/t/test-lib.sh b/t/test-lib.sh index 28315706be..7fda08a90a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -675,7 +675,7 @@ test_run_ () { trace= # 117 is magic because it is unlikely to match the exit # code of other programs - if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)" + if test "OK-117" != "$(test_eval_ "cd() { return 0; } && PATH=/dev/null && export PATH && (exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)" then error "bug in the test script: broken &&-chain or run-away HERE-DOC: $1" fi