From d1a0a9fba05af9994caaa145045c1e11affc385d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 2 Dec 2016 13:52:43 +0100 Subject: [PATCH] localcharset: Avoid theoretical buffer overrun. * lib/localcharset.c (locale_charset) [WINDOWS_NATIVE]: Don't use the return value from setlocale if it would lead to a buffer overrun. --- ChangeLog | 6 ++++++ lib/localcharset.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cdb3cd2451..97fd1708dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-12-02 Bruno Haible + + localcharset: Avoid theoretical buffer overrun. + * lib/localcharset.c (locale_charset) [WINDOWS_NATIVE]: Don't use the + return value from setlocale if it would lead to a buffer overrun. + 2016-12-01 Bruno Haible Relicense some modules under LGPLv2+. diff --git a/lib/localcharset.c b/lib/localcharset.c index ff192f8592..5060aaad6c 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -507,7 +507,7 @@ locale_charset (void) current_locale = setlocale (LC_CTYPE, NULL); pdot = strrchr (current_locale, '.'); - if (pdot) + if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf)) sprintf (buf, "CP%s", pdot + 1); else { -- 2.39.5