summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorcperciva <cperciva@FreeBSD.org>2008-01-14 22:56:05 +0000
committercperciva <cperciva@FreeBSD.org>2008-01-14 22:56:05 +0000
commit533f13b8b27556700f86522a104894994e90f98b (patch)
tree1b8a86b5a99f9962b4056d9beed2656f413eda11 /lib/libc/stdlib
parented5c5e33bff2d3d10c74801eb63aa2dd9574a114 (diff)
downloadFreeBSD-src-533f13b8b27556700f86522a104894994e90f98b.zip
FreeBSD-src-533f13b8b27556700f86522a104894994e90f98b.tar.gz
Fix issues which allow snooping on ptys. [08:01]
Fix an off-by-one error in inet_network(3). [08:02] Security: FreeBSD-SA-08:01.pty Security: FreeBSD-SA-08:02.libc
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/grantpt.c85
1 files changed, 37 insertions, 48 deletions
diff --git a/lib/libc/stdlib/grantpt.c b/lib/libc/stdlib/grantpt.c
index 0ce89fc..ae49127 100644
--- a/lib/libc/stdlib/grantpt.c
+++ b/lib/libc/stdlib/grantpt.c
@@ -75,23 +75,6 @@ __FBSDID("$FreeBSD$");
*/
#define _PATH_PTCHOWN "/usr/libexec/pt_chown"
-/*
- * ISPTM(x) returns 0 for struct stat x if x is not a pty master.
- * The bounds checking may be unnecessary but it does eliminate doubt.
- */
-#define ISPTM(x) (S_ISCHR((x).st_mode) && \
- minor((x).st_rdev) >= 0 && \
- minor((x).st_rdev) < PTY_MAX)
-
-
-static int
-is_pts(int fd)
-{
- int nb;
-
- return (_ioctl(fd, TIOCGPTN, &nb) == 0);
-}
-
int
__use_pts(void)
{
@@ -251,33 +234,43 @@ char *
ptsname(int fildes)
{
static char pty_slave[] = _PATH_DEV PTYS_PREFIX "XY";
+#if 0
static char ptmx_slave[] = _PATH_DEV PTMXS_PREFIX "4294967295";
- char *retval;
+#endif
+ const char *master;
struct stat sbuf;
-
- retval = NULL;
-
- if (_fstat(fildes, &sbuf) == 0) {
- if (!ISPTM(sbuf))
- errno = EINVAL;
- else {
- if (!is_pts(fildes)) {
- (void)snprintf(pty_slave, sizeof(pty_slave),
- _PATH_DEV PTYS_PREFIX "%s",
- devname(sbuf.st_rdev, S_IFCHR) +
- strlen(PTYM_PREFIX));
- retval = pty_slave;
- } else {
- (void)snprintf(ptmx_slave, sizeof(ptmx_slave),
- _PATH_DEV PTMXS_PREFIX "%s",
- devname(sbuf.st_rdev, S_IFCHR) +
- strlen(PTMXM_PREFIX));
- retval = ptmx_slave;
- }
- }
+#if 0
+ int ptn;
+
+ /* Handle pts(4) masters first. */
+ if (_ioctl(fildes, TIOCGPTN, &ptn) == 0) {
+ (void)snprintf(ptmx_slave, sizeof(ptmx_slave),
+ _PATH_DEV PTMXS_PREFIX "%d", ptn);
+ return (ptmx_slave);
}
-
- return (retval);
+#endif
+
+ /* All master pty's must be char devices. */
+ if (_fstat(fildes, &sbuf) == -1)
+ goto invalid;
+ if (!S_ISCHR(sbuf.st_mode))
+ goto invalid;
+
+ /* Check to see if this device is a pty(4) master. */
+ master = devname(sbuf.st_rdev, S_IFCHR);
+ if (strlen(master) != strlen(PTYM_PREFIX "XY"))
+ goto invalid;
+ if (strncmp(master, PTYM_PREFIX, strlen(PTYM_PREFIX)) != 0)
+ goto invalid;
+
+ /* It is, so generate the corresponding pty(4) slave name. */
+ (void)snprintf(pty_slave, sizeof(pty_slave), _PATH_DEV PTYS_PREFIX "%s",
+ master + strlen(PTYM_PREFIX));
+ return (pty_slave);
+
+invalid:
+ errno = EINVAL;
+ return (NULL);
}
/*
@@ -286,18 +279,14 @@ ptsname(int fildes)
int
unlockpt(int fildes)
{
- int retval;
- struct stat sbuf;
/*
* Unlocking a master/slave pseudo-terminal pair has no meaning in a
* non-streams PTY environment. However, we do ensure fildes is a
* valid master pseudo-terminal device.
*/
- if ((retval = _fstat(fildes, &sbuf)) == 0 && !ISPTM(sbuf)) {
- errno = EINVAL;
- retval = -1;
- }
+ if (ptsname(fildes) == NULL)
+ return (-1);
- return (retval);
+ return (0);
}
OpenPOWER on IntegriCloud