* [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf
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
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2009-03-31 23:24 UTC (permalink / raw)
To: René Scharfe; +Cc: git, Junio C Hamano
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf
@ 2009-03-31 23:29 Stephen Boyd
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2009-03-31 23:29 UTC (permalink / raw)
To: rene.scharfe; +Cc: Junio C Hamano, git
Forgot to say this is based on next.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-31 23:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-31 23:29 [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf Stephen Boyd
-- strict thread matches above, loose matches on Subject: below --
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 ` [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf Stephen Boyd
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.