diff options
author | Karl Williamson <khw@cpan.org> | 2014-07-11 15:54:38 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-07-12 08:41:14 -0600 |
commit | 4f72bb37d82e7b97d8480ac800e3937d38084e18 (patch) | |
tree | 3079a5ba58c49753600097a903dfbf517d706d4f /locale.c | |
parent | 0080c90acf59b31e586bcf1d964eaf3d4220e8a5 (diff) | |
download | perl-4f72bb37d82e7b97d8480ac800e3937d38084e18.tar.gz |
locale.c: Use safer code practice
The interior-most function can return NULL. Currently savepv() which is
the next outer function handles this correctly, as does the next outer
function, but it is dangerous to rely on that behavior. So we test for
NULL before calling functions on a NULL ptr.
Diffstat (limited to 'locale.c')
-rw-r--r-- | locale.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -1048,12 +1048,13 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category) if (category != LC_CTYPE) { /* These work only on LC_CTYPE */ /* Get the current LC_CTYPE locale */ - save_ctype_locale = stdize_locale(savepv(setlocale(LC_CTYPE, NULL))); + save_ctype_locale = setlocale(LC_CTYPE, NULL); if (! save_ctype_locale) { DEBUG_L(PerlIO_printf(Perl_debug_log, "Could not find current locale for LC_CTYPE\n")); goto cant_use_nllanginfo; } + save_ctype_locale = stdize_locale(savepv(save_ctype_locale)); /* If LC_CTYPE and the desired category use the same locale, this * means that finding the value for LC_CTYPE is the same as finding @@ -1081,8 +1082,9 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category) # if defined(HAS_NL_LANGINFO) && defined(CODESET) { - char *codeset = savepv(nl_langinfo(CODESET)); + char *codeset = nl_langinfo(CODESET); if (codeset && strNE(codeset, "")) { + codeset = savepv(codeset); /* If we switched LC_CTYPE, switch back */ if (save_ctype_locale) { @@ -1100,7 +1102,6 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category) Safefree(save_input_locale); return is_utf8; } - Safefree(codeset); } # endif @@ -1181,13 +1182,13 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category) if (category != LC_MONETARY) { - save_monetary_locale = stdize_locale(savepv(setlocale(LC_MONETARY, - NULL))); + save_monetary_locale = setlocale(LC_MONETARY, NULL); if (! save_monetary_locale) { DEBUG_L(PerlIO_printf(Perl_debug_log, "Could not find current locale for LC_MONETARY\n")); goto cant_use_monetary; } + save_monetary_locale = stdize_locale(savepv(save_monetary_locale)); if (strNE(save_monetary_locale, save_input_locale)) { if (! setlocale(LC_MONETARY, save_input_locale)) { |