This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New patch for grantpt


On Tue, Dec 18, 2001 at 02:52:45PM +0100, Thorsten Kukuk wrote:
> @@ -16,6 +16,8 @@
>     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
>     02111-1307 USA.  */
>  
> +#include <errno.h>
> +#include <fcntl.h>
>  #include <limits.h>
>  #include <stdlib.h>
>  #include <sys/statfs.h>
> @@ -45,8 +47,20 @@
>  #endif
>    char *buf = _buf;
>  
> -  if (pts_name (fd, &buf, sizeof (_buf)))
> +  /* Check, if the file descriptor is valid. pts_name returns the
> +     wrong errno number, so we cannot use that.  */
> +  if (__builtin_expect (__libc_fcntl (fd, F_GETFD), 0) == -1
> +      && errno == EBADF)
>      return -1;
> +
> +  if (pts_name (fd, &buf, sizeof (_buf)))
> +    {
> +       /* If the filedescriptor is no TTY, grantpt has to set errno
> +          to EINVAL.  */
> +       if (errno == ENOTTY)
> +         __set_errno (EINVAL);
> +       return -1;
> +    }

Cannot the
> +  if (__builtin_expect (__libc_fcntl (fd, F_GETFD), 0) == -1
> +      && errno == EBADF)
test be done only if pts_name failed, so that apps passing correct file
descriptors are not punished?
(saving/restoring errno around it).

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]