beb9e2
From eecfc44fbd6659ed35719038ecf2b029fe20cfd5 Mon Sep 17 00:00:00 2001
beb9e2
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
beb9e2
Date: Mon, 25 Nov 2019 16:48:33 +0100
beb9e2
Subject: [PATCH] Subject: [PATCH] ensure locale_name_on_entry isn't clobbered
beb9e2
MIME-Version: 1.0
beb9e2
Content-Type: text/plain; charset=UTF-8
beb9e2
Content-Transfer-Encoding: 8bit
beb9e2
beb9e2
If the return value of setlocale() is static storage, the call to
beb9e2
setlocale(LC_NUMERIC, "C"); could overwrite it.
beb9e2
beb9e2
If the return value of setlocale() is malloced, the call to
beb9e2
setlocale(LC_NUMERIC, "C"); could free it.
beb9e2
beb9e2
Either way, we need to copy it.  Fixes gh #17054 rt134212
beb9e2
beb9e2
Petr Písař: Ported to version-0.9924 from perl commit
beb9e2
bcb1da5c29c3a2534a0e43874974b83c9c8b174c.
beb9e2
beb9e2
Signed-off-by: Petr Písař <ppisar@redhat.com>
beb9e2
---
beb9e2
 vutil/vutil.c | 6 ++++++
beb9e2
 1 file changed, 6 insertions(+)
beb9e2
beb9e2
diff --git a/vutil/vutil.c b/vutil/vutil.c
beb9e2
index 5d183a0..69c8351 100644
beb9e2
--- a/vutil/vutil.c
beb9e2
+++ b/vutil/vutil.c
beb9e2
@@ -638,6 +638,8 @@ VER_NV:
beb9e2
             if (   strNE(locale_name_on_entry, "C")
beb9e2
                 && strNE(locale_name_on_entry, "POSIX"))
beb9e2
             {
beb9e2
+                /* the setlocale() call might free or overwrite the name */
beb9e2
+                locale_name_on_entry = savepv(locale_name_on_entry);
beb9e2
                 setlocale(LC_NUMERIC, "C");
beb9e2
             }
beb9e2
             else {  /* This value indicates to the restore code that we didn't
beb9e2
@@ -661,6 +663,8 @@ VER_NV:
beb9e2
                 if (   strNE(locale_name_on_entry, "C")
beb9e2
                     && strNE(locale_name_on_entry, "POSIX"))
beb9e2
                 {
beb9e2
+                    /* the setlocale() call might free or overwrite the name */
beb9e2
+                    locale_name_on_entry = savepv(locale_name_on_entry);
beb9e2
                     setlocale(LC_NUMERIC, "C");
beb9e2
                 }
beb9e2
                 else {  /* This value indicates to the restore code that we
beb9e2
@@ -710,6 +714,7 @@ VER_NV:
beb9e2
 
beb9e2
             if (locale_name_on_entry) {
beb9e2
                 setlocale(LC_NUMERIC, locale_name_on_entry);
beb9e2
+                Safefree(locale_name_on_entry);
beb9e2
             }
beb9e2
 
beb9e2
             LC_NUMERIC_UNLOCK;  /* End critical section */
beb9e2
@@ -718,6 +723,7 @@ VER_NV:
beb9e2
 
beb9e2
             if (locale_name_on_entry) {
beb9e2
                 setlocale(LC_NUMERIC, locale_name_on_entry);
beb9e2
+                Safefree(locale_name_on_entry);
beb9e2
                 LC_NUMERIC_UNLOCK;
beb9e2
             }
beb9e2
             else if (locale_obj_on_entry == PL_underlying_numeric_obj) {
beb9e2
-- 
beb9e2
2.21.0
beb9e2