Skip to content

Commit

Permalink
pretty: avoid reading past end-of-string with "%G"
Browse files Browse the repository at this point in the history
If the user asks for --format=%G with nothing else, we
correctly realize that "%G" is not a valid placeholder (it
should be "%G?", "%GK", etc). But we still tell the
strbuf_expand code that we consumed 2 characters, causing it
to jump over the trailing NUL and output garbage.

This also fixes the case where "%GX" would be consumed (and
produce no output). In other cases, we pass unrecognized
placeholders through to the final string.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 17, 2014
1 parent 06ca0f4 commit aa4b78d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
if (c->signature_check.key)
strbuf_addstr(sb, c->signature_check.key);
break;
default:
return 0;
}
return 2;
}
Expand Down
6 changes: 6 additions & 0 deletions t/t7510-signed-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,10 @@ test_expect_success GPG 'show lack of signature with custom format' '
test_cmp expect actual
'

test_expect_success 'unused %G placeholders are passed through' '
echo "%GX %G" >expect &&
git log -1 --format="%GX %G" >actual &&
test_cmp expect actual
'

test_done

0 comments on commit aa4b78d

Please sign in to comment.