Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, nicolas(at)marchildon(dot)net, Bugs for PostgreSQL <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Date: 2013-12-10 00:46:30
Message-ID: 20131210004630.GD2119@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Dec 9, 2013 at 04:35:56PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Updated patch attached, with centralized checking for errno and more
> > consistent behavior for username lookups.
>
> This bit is not good:
>
> + errno = 0; /* clear errno before call */
> + pw = getpwuid(geteuid());
> + if (!pw)
> + {
> + *errstr = psprintf(_("effective user id %d lookup failure: %s"),
> + (int) geteuid(), errno ? strerror(errno) :
> + _("user does not exist"));
>
> The second call of geteuid() could clobber errno before strerror can see it.
> You should compute geteuid() just once and keep it in a variable.

Good point --- fixed.

> Also, I don't think that error message meets our style guidelines.
> Maybe "failed to look up user id %d: ..." ?

OK, updated.

Updated patch attached to Alvaro's email reply.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2013-12-10 00:47:34 Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Previous Message Alvaro Herrera 2013-12-09 21:45:39 Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd