Merge branch 'pw/mailinfo-b-fix' into maint-2.38

Fix a logic in "mailinfo -b" that miscomputed the length of a
substring, which lead to an out-of-bounds access.

* pw/mailinfo-b-fix:
  mailinfo -b: fix an out of bounds access
This commit is contained in:
Junio C Hamano 2022-10-25 17:11:35 -07:00
commit 3694b3844e
2 changed files with 3 additions and 3 deletions

View file

@ -317,7 +317,7 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
pos = strchr(subject->buf + at, ']');
if (!pos)
break;
remove = pos - subject->buf + at + 1;
remove = pos - (subject->buf + at) + 1;
if (!mi->keep_non_patch_brackets_in_subject ||
(7 <= remove &&
memmem(subject->buf + at, remove, "PATCH", 5)))

View file

@ -201,13 +201,13 @@ test_expect_success 'mailinfo -b double [PATCH]' '
test z"$subj" = z"Subject: message"
'
test_expect_failure 'mailinfo -b trailing [PATCH]' '
test_expect_success 'mailinfo -b trailing [PATCH]' '
subj="$(echo "Subject: [other] [PATCH] message" |
git mailinfo -b /dev/null /dev/null)" &&
test z"$subj" = z"Subject: [other] message"
'
test_expect_failure 'mailinfo -b separated double [PATCH]' '
test_expect_success 'mailinfo -b separated double [PATCH]' '
subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
git mailinfo -b /dev/null /dev/null)" &&
test z"$subj" = z"Subject: [other] message"