Message ID | pull.1372.git.1664789011089.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 3ef1494685dea925d4e98ed06d9ea3fb5b3ecb89 |
Headers | show |
Series | mailinfo -b: fix an out of bounds access | expand |
"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes: > We have tests that trigger this bug that were added in ae52d57f0b > (t5100: add some more mailinfo tests, 2017-05-31). The commit message > mentions that they are marked test_expect_failure as they trigger an > assertion in strbuf_splice(). While it is reassuring that > strbuf_splice() detects the problem and dies in retrospect that should > perhaps have warranted a little more investigation. Indeed. > diff --git a/mailinfo.c b/mailinfo.c > index 9621ba62a39..833d28612f7 100644 > --- a/mailinfo.c > +++ b/mailinfo.c > @@ -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; How embarrassing. It really is (&pos[1] - &subject->buf[at]), subtracting from the address of one past the closing ']' and the address of opening '[', so the rewrite is correct. Thanks. > diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh > index cebad1048cf..db11cababd3 100755 > --- a/t/t5100-mailinfo.sh > +++ b/t/t5100-mailinfo.sh > @@ -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" > > base-commit: dda7228a83e2e9ff584bf6adbf55910565b41e14
diff --git a/mailinfo.c b/mailinfo.c index 9621ba62a39..833d28612f7 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -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))) diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index cebad1048cf..db11cababd3 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -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"