Skip to content

Commit 601bb23

Browse files
committed
Merge branch 'pw/mailinfo-b-fix'
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
2 parents 654f5ce + 3ef1494 commit 601bb23

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

mailinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
317317
pos = strchr(subject->buf + at, ']');
318318
if (!pos)
319319
break;
320-
remove = pos - subject->buf + at + 1;
320+
remove = pos - (subject->buf + at) + 1;
321321
if (!mi->keep_non_patch_brackets_in_subject ||
322322
(7 <= remove &&
323323
memmem(subject->buf + at, remove, "PATCH", 5)))

t/t5100-mailinfo.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ test_expect_success 'mailinfo -b double [PATCH]' '
201201
test z"$subj" = z"Subject: message"
202202
'
203203

204-
test_expect_failure 'mailinfo -b trailing [PATCH]' '
204+
test_expect_success 'mailinfo -b trailing [PATCH]' '
205205
subj="$(echo "Subject: [other] [PATCH] message" |
206206
git mailinfo -b /dev/null /dev/null)" &&
207207
test z"$subj" = z"Subject: [other] message"
208208
'
209209

210-
test_expect_failure 'mailinfo -b separated double [PATCH]' '
210+
test_expect_success 'mailinfo -b separated double [PATCH]' '
211211
subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
212212
git mailinfo -b /dev/null /dev/null)" &&
213213
test z"$subj" = z"Subject: [other] message"

0 commit comments

Comments
 (0)