diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-10-11 10:36:11 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-10-11 10:36:11 -0700 |
| commit | 601bb23876bdff60e14b000f1e9f53a5dc4259ff (patch) | |
| tree | badd0c38226449cefc40af773d457a08f93b8474 | |
| parent | 654f5cedbc68f1998e82236987e27213bb858ca0 (diff) | |
| parent | 3ef1494685dea925d4e98ed06d9ea3fb5b3ecb89 (diff) | |
| download | git-601bb23876bdff60e14b000f1e9f53a5dc4259ff.tar.xz | |
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
| -rw-r--r-- | mailinfo.c | 2 | ||||
| -rwxr-xr-x | t/t5100-mailinfo.sh | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/mailinfo.c b/mailinfo.c index 9621ba62a3..833d28612f 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 cebad1048c..db11cababd 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" |
