commit:     04c08067b15933d195d8500eefdc363cb46c1b32
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Aug 22 05:37:33 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Fri Aug 22 22:24:29 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=04c08067

Refrain from calling POSIX::setlocale()

Presently, the POSIX::setlocale() subroutine is used to determine the
currently effective locale. If found to be 'C', the 'LANG' environment
variable shall be unset, along with all variables bearing a prefix of
'LC_'. The idea is to prevent locale-aware subprocesses from trying to
call setlocale(3) to activate a locale that is not yet available.

However, I was recently able to make the Perl 5.40.2 interpreter panic.

Executing: locale-gen '--prefix' '/home/gentoo/gentoo/var/tmp/portage/sy
s-libs/glibc-2.41-r4/image/home/gentoo/gentoo' '--jobs' '12'
locale.c: 3126: panic: Internal length calculation wrong.
"C.utf8" was not entirely added to "C.utf8;C.utf8;C.utf8;C.utf8;C.utf8;C
.utf8;C.utf8;C.utf8;C.utf8;C.utf8;C.ut"; needed=76, had=75; errno=0
Called by locale.c: 4393

 * ERROR: sys-libs/glibc-2.41-r4::gentoo failed (install phase):
 *   locale-gen(1) unexpectedly failed during the src_install phase

Upon the first occurrence of this, I issued the very same locale-gen(8)
command from my interactive shell without issue. I was able to reproduce
the panic several more times, always by building sys-libs/glibc with
portage. Unfortunately, during the course of my investigation, there
came a point at which I was no longer able to reproduce the issue.

Given that locale-gen(8) needs to be robust, refrain from calling
POSIX::setlocale() until such time as the above matter is clarified.
Where necessary, the utilities executed by locale-gen(8) should quietly
fall back to the C locale anyway.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/locale-gen b/locale-gen
index 146a545..2c551ad 100755
--- a/locale-gen
+++ b/locale-gen
@@ -14,7 +14,6 @@ use File::Spec::Functions qw(canonpath catfile catdir 
splitpath);
 use File::Temp qw(tempdir);
 use Getopt::Long ();
 use JSON::PP ();
-use POSIX qw(LC_ALL setlocale);
 
 # Formally stable as of v5.40; sufficiently functional in both v5.36 and v5.38.
 use experimental qw(try);
@@ -29,13 +28,6 @@ my $DEFERRED_SIGNAL = '';
 my $PID = $$;
 my $TEMPDIR;
 
-# For the C locale to be in effect can be a consequence of the user's chosen
-# locale not yet being available. That being the case, unset all environment
-# variables pertaining to locale handling for the benefit of any subprocesses.
-if (setlocale(LC_ALL) eq 'C') {
-       delete @ENV{ grep +( m/^(LANG\z|LC_)/ ), keys %ENV };
-}
-
 # Unset BASH_ENV for security reasons. Even as sh(1), bash acts upon it.
 delete $ENV{'BASH_ENV'};
 

Reply via email to