Skip to content

Commit 9dad073

Browse files
peffgitster
authored andcommitted
sequencer: handle ignore_footer when parsing trailers
The append_signoff() function takes an "ignore_footer" argument, which specifies a number of bytes at the end of the message buffer which should not be considered (they cannot contain trailers, and the trailer is spliced in before them). But to find the existing trailers, it calls into has_conforming_trailer(). That function takes an ignore_footer parameter, but since 967dfd4 (sequencer: use trailer's trailer layout, 2016-11-02) the parameter is completely ignored. The trailer interface we're using takes a single string, with no option to tell it to use part of the string. However, since we have a mutable strbuf, we can work around this by simply overwriting (and later restoring) the boundary with a NUL. I'm not sure if this can actually trigger a bug in practice. It's easy to get a non-zero ignore_footer by doing something like this: git commit -F - --cleanup=verbatim <<-EOF subject body Signed-off-by: me # this looks like a comment, but is actually in the # message! That makes the earlier s-o-b fake. EOF git commit --amend -s There git-commit calls ignore_non_trailer() to count up the "#" cruft, which becomes the ignore_footer header. But it works even without this patch! That's because the trailer code _also_ calls ignore_non_trailer() and skips the cruft, too. So it happens to work because the only callers with a non-zero ignore_footer are using the exact same function that the trailer parser uses internally. And that seems true for all of the current callers, but there's nothing guaranteeing it. We're better off only feeding the correct buffer to the trailer code in the first place. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26e28fe commit 9dad073

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sequencer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,20 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
249249
struct trailer_info info;
250250
size_t i;
251251
int found_sob = 0, found_sob_last = 0;
252+
char saved_char;
252253

253254
opts.no_divider = 1;
254255

256+
if (ignore_footer) {
257+
saved_char = sb->buf[sb->len - ignore_footer];
258+
sb->buf[sb->len - ignore_footer] = '\0';
259+
}
260+
255261
trailer_info_get(&info, sb->buf, &opts);
256262

263+
if (ignore_footer)
264+
sb->buf[sb->len - ignore_footer] = saved_char;
265+
257266
if (info.trailer_start == info.trailer_end)
258267
return 0;
259268

0 commit comments

Comments
 (0)