[glibc] intl: Fix tst-gettext under inherited LC_* environment

Adhemerval Zanella via Glibc-cvs <[email protected]> Mon, 25 May 2026 15:44:07 +0000 (GMT)
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8560164813862088231d1b37aac200cccf9ae64e

commit 8560164813862088231d1b37aac200cccf9ae64e
Author: Adhemerval Zanella <[email protected]>
Date:   Thu May 21 10:26:31 2026 -0300

    intl: Fix tst-gettext under inherited LC_* environment
    
    The final block of tst-gettext unsets LC_ALL plus LC_MESSAGES, LC_CTYPE,
    LC_TIME and LC_NUMERIC, sets LANG=existing-locale, and then expects
    setlocale (LC_ALL, "") to resolve every category through LANG.  Any
    other LC_* category inherited from the invoking shell (e.g. LC_PAPER,
    LC_MONETARY) still takes precedence over LANG, and if it points to a
    locale that is not under the test's LOCPATH the setlocale call fails
    with ENOENT.
    
    Checked on x86_64-linux-gnu.
    Reviewed-by: Carlos O'Donell <[email protected]>

Diff:
---
 intl/tst-gettext.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/intl/tst-gettext.c b/intl/tst-gettext.c
index 8c60e337f3..d8605b2a05 100644
--- a/intl/tst-gettext.c
+++ b/intl/tst-gettext.c
@@ -204,11 +204,22 @@ main (int argc, char *argv[])
       result = 1;
     }
 
-  /* Now the same tests with LANG deciding.  */
+  /* Now the same tests with LANG deciding.  Unset every LC_* category so that
+     values inherited from the invoking shell (e.g. LC_PAPER) cannot leak into
+     setlocale (LC_ALL, "") below and force it to look up a locale that is not
+     under the test's LOCPATH.  */
   unsetenv ("LC_MESSAGES");
   unsetenv ("LC_CTYPE");
   unsetenv ("LC_TIME");
   unsetenv ("LC_NUMERIC");
+  unsetenv ("LC_COLLATE");
+  unsetenv ("LC_MONETARY");
+  unsetenv ("LC_PAPER");
+  unsetenv ("LC_NAME");
+  unsetenv ("LC_ADDRESS");
+  unsetenv ("LC_TELEPHONE");
+  unsetenv ("LC_MEASUREMENT");
+  unsetenv ("LC_IDENTIFICATION");
   setenv ("LANG", "existing-locale", 1);
   check_setlocale (LC_ALL, "");
   /* This is the name of the existing domain with a catalog for the