Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 13 Sep 2018 10:53:14 +0200
From: Szabolcs Nagy <>
Cc: Benjamin Peterson <>
Subject: Re: [PATCH] return EBADF from ttyname_r

* Benjamin Peterson <> [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.

> -	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.

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)

this means users cannot rely on errno value being sane,
so there is not much point trying to do something fancy here.

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.