about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/ptsname.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-08-25 17:57:34 +0000
committerUlrich Drepper <drepper@redhat.com>1999-08-25 17:57:34 +0000
commit2a947279decefbde636886be3ff54333e0c8f4dd (patch)
tree3582524fc632058625762b052f0d127ce8681b6d /sysdeps/unix/sysv/linux/ptsname.c
parent2f44482393e9cf16c75cdf6226d07c69b7f21e95 (diff)
downloadglibc-2a947279decefbde636886be3ff54333e0c8f4dd.tar.gz
glibc-2a947279decefbde636886be3ff54333e0c8f4dd.tar.xz
glibc-2a947279decefbde636886be3ff54333e0c8f4dd.zip
Update.
1999-08-25  Mark Kettenis  <kettenis@gnu.org>

	* sysdeps/unix/sysv/linux/ptsname.c: Add checks to make sure we're
	really dealing with a master pseudo terminal, and really returning
	the name of the associated slave pseudo terminal by checking the
	device number.
	* sysdeps/unix/sysv/linux/pty-private.h: Removed.
	* login/programs/pt_chown.c (do_pt_chown): Don't use unix98_pseudo_p.
Diffstat (limited to 'sysdeps/unix/sysv/linux/ptsname.c')
-rw-r--r--sysdeps/unix/sysv/linux/ptsname.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/ptsname.c b/sysdeps/unix/sysv/linux/ptsname.c
index 5852e2b295..10365792dd 100644
--- a/sysdeps/unix/sysv/linux/ptsname.c
+++ b/sysdeps/unix/sysv/linux/ptsname.c
@@ -29,6 +29,23 @@
 
 #include <stdio-common/_itoa.h>
 
+/* Check if DEV corresponds to a master pseudo terminal device.  */
+#define MASTER_P(Dev)                                                         \
+  (major ((Dev)) == 2                                                         \
+   || (major ((Dev)) == 4 && minor ((Dev)) >= 128 && minor ((Dev)) < 192)     \
+   || (major ((Dev)) >= 128 && major ((Dev)) < 136))
+
+/* Check if DEV corresponds to a master pseudo terminal device.  */
+#define SLAVE_P(Dev)                                                          \
+  (major ((Dev)) == 3                                                         \
+   || (major ((Dev)) == 4 && minor ((Dev)) >= 192 && minor ((Dev)) < 256)     \
+   || (major ((Dev)) >= 136 && major ((Dev)) < 144))
+
+/* Note that major number 4 corresponds to the old BSD style pseudo
+   terminal devices.  As of Linux 2.1.115 these are no longer
+   supported.  They have been replaced by major numbers 2 (masters)
+   and 3 (slaves).  */
+     
 /* Directory where we can find the slave pty nodes.  */
 #define _PATH_DEVPTS "/dev/pts/"
 
@@ -107,7 +124,16 @@ __ptsname_r (int fd, char *buf, size_t buflen)
       if (__fstat (fd, &st) < 0)
 	return errno;
 
+      /* Check if FD really is a master pseudo terminal.  */
+      if (! MASTER_P (st.st_rdev))
+	{
+	  __set_errno (ENOTTY);
+	  return ENOTTY;
+	}
+
       ptyno = minor (st.st_rdev);
+      /* This is for the old BSD pseudo terminals.  As of Linux
+         2.1.115 these are no longer supported.  */
       if (major (st.st_rdev) == 4)
 	ptyno -= 128;
 
@@ -126,6 +152,15 @@ __ptsname_r (int fd, char *buf, size_t buflen)
   if (__xstat (_STAT_VER, buf, &st) < 0)
     return errno;
 
+  /* Check if the name we're about to return really corresponds to a
+     slave pseudo terminal.  */
+  if (! S_ISCHR (st.st_mode) || ! SLAVE_P (st.st_rdev))
+    {
+      /* This really is a configuration problem.  */
+      __set_errno (ENOTTY);
+      return ENOTTY;
+    }
+
   __set_errno (save_errno);
   return 0;
 }