aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2014-05-28 14:41:52 +0200
committerFlorian Weimer <fweimer@redhat.com>2014-07-10 16:29:34 +0200
commitd183645616b0533b3acee28f1a95570bffbdf50f (patch)
treef50571197e197666add2e0da873dfd5fc5763130
parent888c679ba406e89d86bdfbde033e307f5af5198f (diff)
downloadglibc-d183645616b0533b3acee28f1a95570bffbdf50f.tar
glibc-d183645616b0533b3acee28f1a95570bffbdf50f.tar.gz
glibc-d183645616b0533b3acee28f1a95570bffbdf50f.tar.bz2
glibc-d183645616b0533b3acee28f1a95570bffbdf50f.zip
setlocale: Use the heap for the copy of the locale argument
This avoids alloca calls with potentially large arguments.
-rw-r--r--ChangeLog5
-rw-r--r--locale/setlocale.c14
2 files changed, 17 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a1232aa215..5767e5c735 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-07-02 Florian Weimer <fweimer@redhat.com>
+
+ * locale/setlocale.c (setlocale): Use strdup for allocating
+ composite name copy.
+
2014-07-10 Siddhesh Poyarekar <siddhesh@redhat.com>
Sync up with gnulib.
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 94584683f7..6455b8b219 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -272,6 +272,8 @@ setlocale (int category, const char *locale)
of entries of the form `CATEGORY=VALUE'. */
const char *newnames[__LC_LAST];
struct __locale_data *newdata[__LC_LAST];
+ /* Copy of the locale argument, for in-place splitting. */
+ char *locale_copy = NULL;
/* Set all name pointers to the argument name. */
for (category = 0; category < __LC_LAST; ++category)
@@ -281,7 +283,13 @@ setlocale (int category, const char *locale)
if (__glibc_unlikely (strchr (locale, ';') != NULL))
{
/* This is a composite name. Make a copy and split it up. */
- char *np = strdupa (locale);
+ locale_copy = strdup (locale);
+ if (__glibc_unlikely (locale_copy == NULL))
+ {
+ __libc_rwlock_unlock (__libc_setlocale_lock);
+ return NULL;
+ }
+ char *np = locale_copy;
char *cp;
int cnt;
@@ -299,6 +307,7 @@ setlocale (int category, const char *locale)
{
error_return:
__libc_rwlock_unlock (__libc_setlocale_lock);
+ free (locale_copy);
/* Bogus category name. */
ERROR_RETURN;
@@ -391,8 +400,9 @@ setlocale (int category, const char *locale)
/* Critical section left. */
__libc_rwlock_unlock (__libc_setlocale_lock);
- /* Free the resources (the locale path variable). */
+ /* Free the resources. */
free (locale_path);
+ free (locale_copy);
return composite;
}