diff options
-rw-r--r-- | newlib/ChangeLog | 6 | ||||
-rw-r--r-- | newlib/libc/unix/ttyname.c | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index d4e0b68..95f8651 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,9 @@ +2005-07-05 Shaun Jackman <sjackman@gmail.com> + + * newlib/libc/unix/ttyname.c (ttyname): Avoid calling _closedir + twice for the same directory. _closedir calls free, and freeing + the same pointer twice may cause a crash. + 2005-07-06 Aldy Hernandez <aldyh@redhat.com> * configure.host: Added entry for ms1*. diff --git a/newlib/libc/unix/ttyname.c b/newlib/libc/unix/ttyname.c index 258ba25..558f709 100644 --- a/newlib/libc/unix/ttyname.c +++ b/newlib/libc/unix/ttyname.c @@ -56,7 +56,6 @@ ttyname (fd) struct dirent *dirp; DIR *dp; struct stat dsb; - char *rval; /* Must be a terminal. */ if (tcgetattr (fd, &tty) < 0) @@ -69,7 +68,7 @@ ttyname (fd) if ((dp = _opendir (_PATH_DEV)) == NULL) return NULL; - for (rval = NULL; dirp = _readdir (dp);) + while ((dirp = _readdir (dp)) != NULL) { if (dirp->d_ino != sb.st_ino) continue; @@ -78,9 +77,8 @@ ttyname (fd) sb.st_ino != dsb.st_ino) continue; (void) _closedir (dp); - rval = buf; - break; + return buf; } (void) _closedir (dp); - return rval; + return NULL; } |