From: Stephen Boyd <bebarino@gmail.com>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf
Date: Tue, 31 Mar 2009 16:24:38 -0700 [thread overview]
Message-ID: <1238541878-11025-1-git-send-email-bebarino@gmail.com> (raw)
In-Reply-To: <49D2968D.6010108@lsrfire.ath.cx>
If the subject line is '...' the strbuf will be accessed before the
first dot is added; potentially changing the strbuf passed into the
function or accessing sb->buf[-1] if it was originally empty.
Reported-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>
---
I was thinking about this today actually. Thanks.
With regards to the isalnum(), I kept the original code because I wasn't sure
if the functionality would be different.
pretty.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/pretty.c b/pretty.c
index c57cef4..a0ef356 100644
--- a/pretty.c
+++ b/pretty.c
@@ -502,6 +502,7 @@ static int istitlechar(char c)
static void format_sanitized_subject(struct strbuf *sb, const char *msg)
{
size_t trimlen;
+ size_t start_len = sb->len;
int space = 2;
for (; *msg && *msg != '\n'; msg++) {
@@ -519,8 +520,9 @@ static void format_sanitized_subject(struct strbuf *sb, const char *msg)
/* trim any trailing '.' or '-' characters */
trimlen = 0;
- while (sb->buf[sb->len - 1 - trimlen] == '.'
- || sb->buf[sb->len - 1 - trimlen] == '-')
+ while (sb->len - trimlen > start_len &&
+ (sb->buf[sb->len - 1 - trimlen] == '.'
+ || sb->buf[sb->len - 1 - trimlen] == '-'))
trimlen++;
strbuf_remove(sb, sb->len - trimlen, trimlen);
}
--
1.6.2
next prev parent reply other threads:[~2009-03-31 23:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-22 4:32 [PATCHv2 0/3] format-patch --attach/--inline use filename instead of SHA1 Stephen Boyd
2009-03-22 4:32 ` [PATCHv2 1/3] format-patch: create patch filename in one function Stephen Boyd
2009-03-22 4:32 ` [PATCHv2 2/3] format-patch: --attach/inline uses filename instead of SHA1 Stephen Boyd
2009-03-22 4:32 ` [PATCHv2 3/3] format-patch: --numbered-files and --stdout aren't mutually exclusive Stephen Boyd
2009-03-22 5:44 ` Junio C Hamano
2009-03-22 5:36 ` [PATCHv2 2/3] format-patch: --attach/inline uses filename instead of SHA1 Junio C Hamano
2009-03-22 5:31 ` [PATCHv2 1/3] format-patch: create patch filename in one function Junio C Hamano
2009-03-22 5:59 ` Stephen Boyd
2009-03-22 6:53 ` Junio C Hamano
2009-03-22 6:56 ` Stephen Boyd
2009-03-22 8:07 ` Junio C Hamano
2009-03-23 2:14 ` [PATCHv3 0/6] format-patch --attach/--inline uses filename not SHA1 Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 1/6] pretty.c: add %f format specifier to format_commit_message() Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 2/6] format-patch: construct patch filename in one function Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 3/6] format-patch: pass a commit to reopen_stdout() Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 4/6] format-patch: move get_patch_filename() into log-tree Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 5/6] format-patch: --attach/inline uses filename instead of SHA1 Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 6/6] format-patch: --numbered-files and --stdout aren't mutually exclusive Stephen Boyd
2009-03-31 22:17 ` [PATCHv3 1/6] pretty.c: add %f format specifier to format_commit_message() René Scharfe
2009-03-31 23:24 ` Stephen Boyd [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-03-31 23:29 [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1238541878-11025-1-git-send-email-bebarino@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=rene.scharfe@lsrfire.ath.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).