Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1536855940.1011892.1507091216.5EC78F32@webmail.messagingengine.com>
Date: Thu, 13 Sep 2018 09:25:40 -0700
From: Benjamin Peterson <benjamin@...hon.org>
To: Rich Felker <dalias@...c.org>, musl@...ts.openwall.com
Subject: Re: [PATCH] return EBADF from ttyname_r

Thank you for the feedback.

On Thu, Sep 13, 2018, at 08:29, Rich Felker wrote:
> On Thu, Sep 13, 2018 at 10:53:14AM +0200, Szabolcs Nagy wrote:
> > * Benjamin Peterson <benjamin@...hon.org> [2018-09-12 17:34:24 -0700]:
> > > POSIX allows ttyname(_r) to return EBADF if passed file descriptor is invalid.
> > 
> > i think EBADF is always a 'may fail' in posix, so not strictly required.

Right, I don't claim this patch fixes a bug; just makes the error reporting more precise.

> > 
> > > -	if (!isatty(fd)) return ENOTTY;
> > > +	if (!isatty(fd)) {
> > > +		if (errno == EBADF) return EBADF;
> > > +		return ENOTTY;
> > > +	}
> > 
> > musl isatty uses __syscall which does not set errno so this is wrong.

Good point.

> > 
> > note that on glibc isatty sets errno according what the kernel returns
> > however linux has different code paths in ioctl for different type of
> > fds and in some cases it can fail in interesting ways (iirc on a socket
> > fd it will fail with EINVAL or EFAULT at least on some linux versions
> > and it can even spuriously succeed on non-tty fds because the TCGETS
> > ioctl command was reused on some audio device to do different things)
> 
> That's why we no longer use TCGETS but rather TIOCGWINSZ.
> 
> > this means users cannot rely on errno value being sane,
> > so there is not much point trying to do something fancy here.
> 
> I'm not sure this is actually an issue anymore, but if it is, we
> should simply translate anything other than EBADF to ENOTTY. There is
> no other meaningful error. Either the fd is valid or it's not, and if
> it is valid, either it is a tty or it's not.

I will send another patch to this effect.

> 
> Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.