git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t6112: avoid tilde expansion

From
Elijah Newren <newren@gmail.com>
Date
Apr 19, 2026, 01:26 UTC
Message-ID
<CABPp-BGV4DGwoSDCjjW2NWBhWXNDfeXwb-tPWSH_13mF0DCiRg@mail.gmail.com>
In-Reply-To
<20260418163236.2382826-1-szeder.dev@gmail.com>
On Sat, Apr 18, 2026 at 9:33 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:
Show 20 quoted lines
>
> e987df5fe6 (list-objects-filter: implement composite filters,
> 2019-06-27) introduced a test to "t6112-rev-list-filters-objects.sh"
> that checks the output of a Git command with the following commands:
>
>   grep ~$omitted_1 actual &&
>   grep ~$omitted_2 actual &&
>   grep ~$omitted_3 actual &&
>
> Since the leading tilde in the pattern is not quoted/escaped, it is
> subject to tilde expansion.  So if the system has a user whose
> username happens to be equal to the content of one of those
> "$omitted_*" variables, then "grep" would look for the user's home
> directory.  Luckily, those variables contain object hashes, so this is
> not very likely.
>
> Furthermore, Bash versions v5.0 and earlier seem to be buggy and don't
> handle this particular tilde expansion very well, and either segfault
> right away or, in case of v3.2, get stuck in an endless loop and
> segfault upon receiving ctrl-c.
Interesting find on the bash segfault behavior.
Show 26 quoted lines
> Quote those words starting with a tilde to avoid these issues.
>
> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
> ---
>  t/t6112-rev-list-filters-objects.sh | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh
> index 39211ef989..e0a825bccf 100755
> --- a/t/t6112-rev-list-filters-objects.sh
> +++ b/t/t6112-rev-list-filters-objects.sh
> @@ -623,9 +623,9 @@ test_expect_success 'verify collecting omits in combined: filter' '
>         omitted_2=$(echo a     | git hash-object --stdin) &&
>         omitted_3=$(echo abcde | git hash-object --stdin) &&
>
> -       grep ~$omitted_1 actual &&
> -       grep ~$omitted_2 actual &&
> -       grep ~$omitted_3 actual &&
> +       grep "~$omitted_1" actual &&
> +       grep "~$omitted_2" actual &&
> +       grep "~$omitted_3" actual &&
>         test_line_count = 3 actual
>  '
>
> --
> 2.54.0.rc2.650.gc37764ecfc

Looks good to me. I wasn't able to find any other unquoted ~$ uses in the testsuite except mid-word (e.g. HEAD~$i), though I suspect your version of bash seg-faulting is a better check than my grep-fu anyway.

Previous: SZEDER GáborNext: SZEDER Gábor
Message 2 of 4 in “t6112: avoid tilde expansion”
  1. t6112: avoid tilde expansionSZEDER Gábor, Apr 18, 2026
  2. Elijah NewrenApr 19, 2026
  3. SZEDER GáborApr 20, 2026
  4. t6112: avoid tilde expansionSZEDER Gábor, Apr 21, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.