From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11479 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix errno not being set to ERANGE by getgr, getpw, and getspnam Date: Wed, 14 Jun 2017 20:05:18 -0400 Message-ID: <20170615000518.GK1627@brightrain.aerifal.cx> References: <20170609000030.GM1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1497485131 20395 195.159.176.226 (15 Jun 2017 00:05:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 15 Jun 2017 00:05:31 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11492-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 15 02:05:27 2017 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.84_2) (envelope-from ) id 1dLIHv-00054s-BA for gllmg-musl@m.gmane.org; Thu, 15 Jun 2017 02:05:27 +0200 Original-Received: (qmail 26541 invoked by uid 550); 15 Jun 2017 00:05:30 -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 26523 invoked from network); 15 Jun 2017 00:05:30 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11479 Archived-At: On Sun, Jun 11, 2017 at 12:59:51PM -0400, Rudolph Pereira wrote: > Hi Rich, > > thanks for the feedback. I've attached a patch that implements errno > setting as you suggested, other than a couple of cases where the code > immediately returns. This also brings it in line with existing code > (in __getpw_a/__getgr_a) so makes things more consistent. Please see > attached - note this is against HEAD. It looks like you omitted the change to getgr_r.c corresponding to this one for getpw_r.c: > diff --git a/src/passwd/getpw_r.c b/src/passwd/getpw_r.c > index e8cc811..0c87ab0 100644 > --- a/src/passwd/getpw_r.c > +++ b/src/passwd/getpw_r.c > @@ -27,6 +27,7 @@ static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, si > } > free(line); > pthread_setcancelstate(cs, 0); > + if (rv) errno = rv; > return rv; > } Also: > diff --git a/src/passwd/getspnam_r.c b/src/passwd/getspnam_r.c > index 9233952..47ce3d3 100644 > --- a/src/passwd/getspnam_r.c > +++ b/src/passwd/getspnam_r.c > @@ -72,14 +72,24 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct > > /* Disallow potentially-malicious user names */ > if (*name=='.' || strchr(name, '/') || !l) > + { > + errno = EINVAL; > return EINVAL; > + } Please use consistent style for braces (open brace on if line). Alternatively (if you don't balk at the style; not sure if others will like it), this works: - return EINVAL; + return errno = EINVAL; Rich