summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-06-15 22:56:51 -0700
committerPetr Baudis <pasky@suse.cz>2009-06-16 12:24:54 +0200
commitc8bfc696298620bc1199996f5d836ce837248b0b (patch)
tree03ff83547bc721b5563babf744195e4ccf7f477b
parent2a31410e40b61c47ab4c5283c25cea2c5405d757 (diff)
downloadglibc-c8bfc696298620bc1199996f5d836ce837248b0b.tar.gz
glibc-c8bfc696298620bc1199996f5d836ce837248b0b.tar.xz
glibc-c8bfc696298620bc1199996f5d836ce837248b0b.zip
Fix permission of slave device on devpts if necessary.
If devptr is misconfigured the slave device permission after grantpt
might not be 0620.  BZ #10166
(cherry picked from commit 292e3abebff9f94ca47c1a725a691cb6ed6cff5f)
-rw-r--r--ChangeLog5
-rw-r--r--sysdeps/unix/sysv/linux/grantpt.c13
2 files changed, 15 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b1ba1459f8..7bec39af09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-06-15  Ulrich Drepper  <drepper@redhat.com>
 
+	[BZ #10166]
+	* sysdeps/unix/sysv/linux/grantpt.c: If slave device is on devpts or
+	devfs, the mode might not be correct.  Check it and return only if it
+	is correct.
+
 	[BZ #10183]
 	* posix/tst-cpucount.c: Don't try more than CPU_SETSIZE bits.
 
diff --git a/sysdeps/unix/sysv/linux/grantpt.c b/sysdeps/unix/sysv/linux/grantpt.c
index b894b8b631..c858f89c8b 100644
--- a/sysdeps/unix/sysv/linux/grantpt.c
+++ b/sysdeps/unix/sysv/linux/grantpt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001, 2002, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -70,9 +70,16 @@ grantpt (int fd)
     return -1;
 
   /* If the slave pseudo terminal lives on a `devpts' filesystem, the
-     ownership and access permission are already set.  */
+     ownership is already set and the access permission might already
+     be set.  */
   if (fsbuf.f_type == DEVPTS_SUPER_MAGIC || fsbuf.f_type == DEVFS_SUPER_MAGIC)
-    return 0;
+    {
+      struct stat64 st;
+
+      if (fstat (fd, &st) == 0
+	  && (st.st_mode & ACCESSPERMS) == (S_IRUSR|S_IWUSR|S_IWGRP))
+	return 0;
+    }
 
   return __unix_grantpt (fd);
 }