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

Re: [PATCH v3] gettext.c: detect the vsnprintf bug at runtime

From
Trần Ngọc Quân <vnwildman@gmail.com>
Date
Dec 2, 2013, 00:31 UTC
Message-ID
<529BD4E1.8040408@gmail.com>
In-Reply-To
<1385865938-16392-1-git-send-email-pclouds@gmail.com>
On 01/12/2013 09:45, Nguyễn Thái Ngọc Duy wrote:
Show 40 quoted lines
> Bug 6530 [1] in glibc causes "git show v0.99.6~1" to fail with error
> "your vsnprintf is broken". The workaround avoids that, but it
> corrupts system error messages in non-C locales.
>
> The bug has been fixed since 2.17. We could know running glibc version
> with gnu_get_libc_version(). But version is not a sure way to detect
> the bug because downstream may back port the fix to older versions. Do
> a runtime test that immitates the call flow that leads to "your
> vsnprintf is broken". Only enable the workaround if the test fails.
>
> Tested on Gentoo Linux, glibc 2.16.0 and 2.17, amd64.
>
> [1] http://sourceware.org/bugzilla/show_bug.cgi?id=6530
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  v3 goes with runtime test instead of version check.
>
>  gettext.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/gettext.c b/gettext.c
> index 71e9545..eed7c7f 100644
> --- a/gettext.c
> +++ b/gettext.c
> @@ -29,6 +29,17 @@ int use_gettext_poison(void)
>  #endif
>  
>  #ifndef NO_GETTEXT
> +static int test_vsnprintf(const char *fmt, ...)
> +{
> +	char buf[26];
> +	int ret;
> +	va_list ap;
> +	va_start(ap, fmt);
> +	ret = vsnprintf(buf, sizeof(buf), fmt, ap);
> +	va_end(ap);
> +	return ret;
> +}
> +

this function alway run each time we run git commad while libc is static. It is waste.

Show 6 quoted lines
> +	/* the string is taken from v0.99.6~1 */
> +	if (test_vsnprintf("%.*s", 13, "David_K\345gedal") < 0)
> +		setlocale(LC_CTYPE, "C");
>  }
>  
>  void git_setup_gettext(void)
I suggest use C preprocessor instead. The person who complete git (make debian, rpm etc. package) decide  enable it or not (disable by default). Most of people use git from distribution instead of complete it from source.
#ifndef VSNPRINTF_OK
	setlocale(LC_CTYPE, "C");
#endif
-- 
Trần Ngọc Quân.
Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 8 of 12 in “gettext.c: only work around the vsnprintf bug on glibc < 2.17”
  1. gettext.c: only work around the vsnprintf bug on glibc < 2.17Nguyễn Thái Ngọc Duy, Nov 30, 2013
  2. Andreas SchwabNov 30, 2013
  3. gettext.c: only work around the vsnprintf bug on glibc < 2.17Nguyễn Thái Ngọc Duy, Nov 30, 2013
  4. Torsten BögershausenNov 30, 2013
  5. Torsten BögershausenNov 30, 2013
  6. Duy NguyenDec 1, 2013
  7. gettext.c: detect the vsnprintf bug at runtimeNguyễn Thái Ngọc Duy, Dec 1, 2013
  8. Trần Ngọc QuânDec 2, 2013
  9. Duy NguyenDec 2, 2013
  10. Trần Ngọc QuânDec 2, 2013
  11. Trần Ngọc QuânDec 2, 2013
  12. Duy NguyenDec 2, 2013

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.