From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
To: musl@lists.openwall.com
Cc: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Subject: [PATCH] locale: ensure dcngettext() preserves errno
Date: Sun, 27 Jan 2019 21:34:57 -0600 [thread overview]
Message-ID: <20190128033457.10635-1-AWilcox@Wilcox-Tech.com> (raw)
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
next reply other threads:[~2019-01-28 3:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 3:34 A. Wilcox [this message]
2019-01-28 3:38 ` A. Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190128033457.10635-1-AWilcox@Wilcox-Tech.com \
--to=awilcox@wilcox-tech.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).