From: Ulrich Drepper Date: Thu, 1 Apr 1999 09:33:06 +0000 (+0000) Subject: Update. X-Git-Tag: cvs/glibc-2_1_1~192 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7081e0a34c10eb54ab5f4ca62c5f4f4fa222cbff;p=thirdparty%2Fglibc.git Update. 1999-04-01 Andreas Jaeger * sysdeps/unix/sysv/linux/ttyname.c (ttyname): Terminate the string. * sysdeps/unix/sysv/linux/ttyname_r.c (__ttyname_r): Likewise. --- diff --git a/ChangeLog b/ChangeLog index d40697a8c60..643dd5a0c76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +1999-04-01 Andreas Jaeger + + * sysdeps/unix/sysv/linux/ttyname.c (ttyname): Terminate the + string. + * sysdeps/unix/sysv/linux/ttyname_r.c (__ttyname_r): Likewise. + 1999-04-01 Ulrich Drepper * iconvdata/TESTS: Add ISO-8859-14 and ISO-8859-15. diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c index 20c794daf4d..0dd9c704af7 100644 --- a/sysdeps/unix/sysv/linux/ttyname.c +++ b/sysdeps/unix/sysv/linux/ttyname.c @@ -112,6 +112,7 @@ ttyname (fd) int dostat = 0; char *name; int save = errno; + int len; if (!__isatty (fd)) return NULL; @@ -130,10 +131,17 @@ ttyname (fd) } } - if (__readlink (procname, buf, buflen) != -1 + len = __readlink (procname, buf, buflen); + if (len != -1 /* This is for Linux 2.0. */ && buf[0] != '[') - return buf; + { + if (len >= buflen) + return NULL; + /* readlink need not terminate the string. */ + buf[len] = '\0'; + return buf; + } if (__fxstat (_STAT_VER, fd, &st) < 0) return NULL; diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c index b92c712fcc4..9a0ce4cea92 100644 --- a/sysdeps/unix/sysv/linux/ttyname_r.c +++ b/sysdeps/unix/sysv/linux/ttyname_r.c @@ -134,7 +134,10 @@ __ttyname_r (fd, buf, buflen) ret = __readlink (procname, buf, buflen - 1); if (ret != -1 && buf[0] != '[') - return 0; + { + buf[ret] = '\0'; + return 0; + } if (ret == -1 && errno == ENAMETOOLONG) { __set_errno (ERANGE);