git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] format_sanitized_subject: Don't trim past initial length of strbuf

From
Stephen Boyd <bebarino@gmail.com>
Date
Mar 31, 2009, 23:24 UTC
Message-ID
<1238541878-11025-1-git-send-email-bebarino@gmail.com>
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
Previous: René Scharfe
Message 20 of 20 in “[PATCHv2 0/3] format-patch --attach/--inline use filename instead of SHA1”
  1. Stephen BoydMar 22, 2009
  2. 1/3 format-patch: create patch filename in one functionStephen Boyd, Mar 22, 2009
  3. 2/3 format-patch: --attach/inline uses filename instead of SHA1Stephen Boyd, Mar 22, 2009
  4. 3/3 format-patch: --numbered-files and --stdout aren't mutually exclusiveStephen Boyd, Mar 22, 2009
  5. Junio C HamanoMar 22, 2009
  6. Junio C HamanoMar 22, 2009
  7. Junio C HamanoMar 22, 2009
  8. Stephen BoydMar 22, 2009
  9. Junio C HamanoMar 22, 2009
  10. Stephen BoydMar 22, 2009
  11. Junio C HamanoMar 22, 2009
  12. 0/6 format-patch --attach/--inline uses filename not SHA1Stephen Boyd, Mar 23, 2009
  13. 1/6 pretty.c: add %f format specifier to format_commit_message()Stephen Boyd, Mar 23, 2009
  14. 2/6 format-patch: construct patch filename in one functionStephen Boyd, Mar 23, 2009
  15. 3/6 format-patch: pass a commit to reopen_stdout()Stephen Boyd, Mar 23, 2009
  16. 4/6 format-patch: move get_patch_filename() into log-treeStephen Boyd, Mar 23, 2009
  17. 5/6 format-patch: --attach/inline uses filename instead of SHA1Stephen Boyd, Mar 23, 2009
  18. 6/6 format-patch: --numbered-files and --stdout aren't mutually exclusiveStephen Boyd, Mar 23, 2009
  19. René ScharfeMar 31, 2009
  20. format_sanitized_subject: Don't trim past initial length of strbufStephen Boyd, Mar 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.