]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix getttyname on Linux when called for different devices.
authorUlrich Drepper <drepper@redhat.com>
Thu, 29 Oct 2009 18:02:34 +0000 (11:02 -0700)
committerUlrich Drepper <drepper@redhat.com>
Thu, 29 Oct 2009 18:02:34 +0000 (11:02 -0700)
If a second call to ttyname is not for the same type of device (e.g.,
serial vs ptty) the prefix of the buffer was wrong.  Don't rely on
the previous content, always reinitialize it.

ChangeLog
sysdeps/unix/sysv/linux/ttyname.c

index a169cee2c589f54b22748e6df8730a09054fc034..25bb3255df77e4f84f383abf0ec3011b409b2544 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,13 @@
 2009-10-29  Ulrich Drepper  <drepper@redhat.com>
 
+       [BZ #10784]
+       * sysdeps/unix/sysv/linux/ttyname.c (getttyname): Always copy name
+       of the directory we look at into the static buffer if there is one
+       at the start of the loop.
+
        [BZ #10789]
        * sysdeps/generic/netinet/ip.h: Define IPTOS_ENC* and IPTOS_DSCP*
-       macros.  Patch by  Philip Prindeville <philipp@redfish-solutions.com>.
+       macros.  Patch by Philip Prindeville <philipp@redfish-solutions.com>.
 
        [BZ #10840]
        * sysdeps/unix/sysv/linux/kernel-features.h: Define
index 1b797875155e1474822af604245f2e02e2f5b319..69af6adc65126c1d0260fc6f68a0a4b59a63282a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,1996-2002,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,1996-2002,2006,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
@@ -59,6 +59,11 @@ getttyname (const char *dev, dev_t mydev, ino64_t myino, int save, int *dostat)
       return NULL;
     }
 
+  /* Prepare for the loop.  If we already have a buffer copy the directory
+     name we look at into it.  */
+  if (devlen < namelen)
+    *((char *) __mempcpy (getttyname_name, dev, devlen - 1)) = '/';
+
   while ((d = __readdir64 (dirstream)) != NULL)
     if ((d->d_fileno == myino || *dostat)
        && strcmp (d->d_name, "stdin")