]> Savannah Git Hosting - gnulib.git/commitdiff
localcharset: Avoid theoretical buffer overrun.
authorBruno Haible <bruno@clisp.org>
Fri, 2 Dec 2016 12:52:43 +0000 (13:52 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 2 Dec 2016 12:52:43 +0000 (13:52 +0100)
* lib/localcharset.c (locale_charset) [WINDOWS_NATIVE]: Don't use the
return value from setlocale if it would lead to a buffer overrun.

ChangeLog
lib/localcharset.c

index cdb3cd24515a1761ee5a1e327ebbe40d118bed5a..97fd1708dc2ae3ea094877dcf6f714ec129d97bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-02  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        Relicense some modules under LGPLv2+.
index ff192f859283c960bb160b98aacb6d872efadc52..5060aaad6c0a266e53fef542f505b3d0e9eb71ee 100644 (file)
@@ -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
     {