From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13657 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "A. Wilcox" Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] locale: ensure dcngettext() preserves errno Date: Sun, 27 Jan 2019 21:34:57 -0600 Message-ID: <20190128033457.10635-1-AWilcox@Wilcox-Tech.com> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="107462"; mail-complaints-to="usenet@blaine.gmane.org" Cc: "A. Wilcox" To: musl@lists.openwall.com Original-X-From: musl-return-13673-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jan 28 04:37:20 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1gnxjc-000Rrt-AL for gllmg-musl@m.gmane.org; Mon, 28 Jan 2019 04:37:20 +0100 Original-Received: (qmail 1439 invoked by uid 550); 28 Jan 2019 03:37:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1402 invoked from network); 28 Jan 2019 03:37:15 -0000 X-Mailer: git-send-email 2.19.2 Xref: news.gmane.org gmane.linux.lib.musl.general:13657 Archived-At: Some packages call gettext to format a message to be sent to strerror(3). If the currently set user locale points to a non-existent .mo file, open(2) via __map_file() in dcngettext() will set errno to ENOENT. Simple test case is to compile coreutils with NLS enabled and then run `ls /root` as an unprivileged user. Before this commit: ls: cannot open directory '/root': No such file or directory After this commit: ls: cannot open directory '/root': Permission denied Originally reported by aranea on #Adelie. --- src/locale/dcngettext.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/locale/dcngettext.c b/src/locale/dcngettext.c index 8b891d00..4c304393 100644 --- a/src/locale/dcngettext.c +++ b/src/locale/dcngettext.c @@ -122,6 +122,7 @@ char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, const struct __locale_map *lm; size_t domlen; struct binding *q; + int old_errno = errno; if ((unsigned)category >= LC_ALL) goto notrans; @@ -138,6 +139,7 @@ char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, lm = loc->cat[category]; if (!lm) { notrans: + errno = old_errno; return (char *) ((n == 1) ? msgid1 : msgid2); } @@ -250,6 +252,7 @@ notrans: trans += l+1; } } + errno = old_errno; return (char *)trans; } -- 2.19.2