Skip to content

Commit d1c851a

Browse files
tonycozLeont
authored andcommitted
ensure locale_name_on_entry isn't clobbered
If the return value of setlocale() is static storage, the call to setlocale(LC_NUMERIC, "C"); could overwrite it. If the return value of setlocale() is malloced, the call to setlocale(LC_NUMERIC, "C"); could free it. Either way, we need to copy it.
1 parent fd2d97d commit d1c851a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vutil/vutil.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
638638
if ( strNE(locale_name_on_entry, "C")
639639
&& strNE(locale_name_on_entry, "POSIX"))
640640
{
641+
/* the setlocale() call might free or overwrite the name */
642+
locale_name_on_entry = savepv(locale_name_on_entry);
641643
setlocale(LC_NUMERIC, "C");
642644
}
643645
else { /* This value indicates to the restore code that we didn't
@@ -661,6 +663,8 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
661663
if ( strNE(locale_name_on_entry, "C")
662664
&& strNE(locale_name_on_entry, "POSIX"))
663665
{
666+
/* the setlocale() call might free or overwrite the name */
667+
locale_name_on_entry = savepv(locale_name_on_entry);
664668
setlocale(LC_NUMERIC, "C");
665669
}
666670
else { /* This value indicates to the restore code that we
@@ -710,6 +714,7 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
710714

711715
if (locale_name_on_entry) {
712716
setlocale(LC_NUMERIC, locale_name_on_entry);
717+
Safefree(locale_name_on_entry);
713718
}
714719

715720
LC_NUMERIC_UNLOCK; /* End critical section */
@@ -718,6 +723,7 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
718723

719724
if (locale_name_on_entry) {
720725
setlocale(LC_NUMERIC, locale_name_on_entry);
726+
Safefree(locale_name_on_entry);
721727
LC_NUMERIC_UNLOCK;
722728
}
723729
else if (locale_obj_on_entry == PL_underlying_numeric_obj) {

0 commit comments

Comments
 (0)