diff options
author | ZheNing Hu <adlternative@gmail.com> | 2021-05-11 15:35:20 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-05-11 23:13:14 (GMT) |
commit | 1e1c4c5eac972516db47394ae94a52a3b97cb41a (patch) | |
tree | 2314cc8e21e861a9030c0a961d437e3717f753b6 /t/t6302-for-each-ref-filter.sh | |
parent | 6ff7f460394745395f3eec1e414ad2300c6a402f (diff) | |
download | git-1e1c4c5eac972516db47394ae94a52a3b97cb41a.zip git-1e1c4c5eac972516db47394ae94a52a3b97cb41a.tar.gz git-1e1c4c5eac972516db47394ae94a52a3b97cb41a.tar.bz2 |
ref-filter: fix read invalid union member bug
used_atom.u is an union, and it has different members depending on
what atom the auxiliary data the union part of the "struct
used_atom" wants to record. At most only one of the members can be
valid at any one time. Since the code checks u.remote_ref without
even making sure if the atom is "push" or "push:" (which are only
two cases that u.remote_ref.push becomes valid), but u.remote_ref
shares the same storage for other members of the union, the check
was reading from an invalid member, which was the bug.
Modify the condition here to check whether the atom name
equals to "push" or starts with "push:", to avoid reading the
value of invalid member of the union.
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
[jc: further test fixes]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6302-for-each-ref-filter.sh')
-rwxr-xr-x | t/t6302-for-each-ref-filter.sh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh index 35408d5..529ca55 100755 --- a/t/t6302-for-each-ref-filter.sh +++ b/t/t6302-for-each-ref-filter.sh @@ -113,6 +113,25 @@ test_expect_success '%(color) must fail' ' test_must_fail git for-each-ref --format="%(color)%(refname)" ' +test_expect_success '%(color:#aa22ac) must succeed' ' + test_when_finished rm -rf test && + git init test && + ( + cd test && + test_commit initial && + git branch -M main && + cat >expect <<-\EOF && + refs/heads/main + refs/tags/initial + EOF + git remote add origin nowhere && + git config branch.main.remote origin && + git config branch.main.merge refs/heads/main && + git for-each-ref --format="%(color:#aa22ac)%(refname)" >actual && + test_cmp expect actual + ) +' + test_expect_success 'left alignment is default' ' cat >expect <<-\EOF && refname is refs/heads/master |refs/heads/master |