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

[PATCH v3 1/2] bisect_next_all(): fix bisect crash when used the gettext translation

From
Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
Date
Feb 16, 2017, 23:32 UTC
Message-ID
<20170216233249.24757-2-franchesko.salias.hudro.pedros@gmail.com>
In-Reply-To
<20170216233249.24757-1-franchesko.salias.hudro.pedros@gmail.com>

The buffer steps_msg[32] is too small. Translated "(roughly %d step)" string can not be located in the buffer.

Solution: using xstrfmt which dynamically allocates memory.

Dummy solution: just increase steps_msg size but is not safe. That feels pretty hacky, though. In practice the set of translations is contained, but it doesn't have to be (and certainly nobody would notice if a new translation was added with a longer name until a user complained).

Reproduce bug: "LANG=ru_RU.UTF8 git bisect start v4.9 v4.8" on linux sources.
Signed-off-by: Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
---
 bisect.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/bisect.c b/bisect.c
index 21bc6daa4..787543cad 100644
--- a/bisect.c
+++ b/bisect.c
@@ -940,7 +940,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
 	struct commit_list *tried;
 	int reaches = 0, all = 0, nr, steps;
 	const unsigned char *bisect_rev;
-	char steps_msg[32];
+	char *steps_msg;
 
 	read_bisect_terms(&term_bad, &term_good);
 	if (read_bisect_refs())
@@ -990,14 +990,15 @@ int bisect_next_all(const char *prefix, int no_checkout)
 
 	nr = all - reaches - 1;
 	steps = estimate_bisect_steps(all);
-	xsnprintf(steps_msg, sizeof(steps_msg),
-		  Q_("(roughly %d step)", "(roughly %d steps)", steps),
-		  steps);
+
+	steps_msg = xstrfmt(Q_("(roughly %d step)", "(roughly %d steps)",
+		  steps), steps);
 	/* TRANSLATORS: the last %s will be replaced with
 	   "(roughly %d steps)" translation */
 	printf(Q_("Bisecting: %d revision left to test after this %s\n",
 		  "Bisecting: %d revisions left to test after this %s\n",
 		  nr), nr, steps_msg);
+	free(steps_msg);
 
 	return bisect_checkout(bisect_rev, no_checkout);
 }
-- 
2.11.1
Previous: Maxim MoseychukNext: Maxim Moseychuk
Message 2 of 3 in “Fix l10n”
  1. 0/2 Fix l10nMaxim Moseychuk, Feb 16, 2017
  2. 1/2 bisect_next_all(): fix bisect crash when used the gettext translationMaxim Moseychuk, Feb 16, 2017
  3. 2/2 stop_progress_msg(): simplification functionMaxim Moseychuk, Feb 16, 2017

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.