summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/ttyname.c
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2016-06-27 16:52:30 +0000
committerespie <espie@openbsd.org>2016-06-27 16:52:30 +0000
commit4eec04afc3730282d2e54e2ec3e899f7d7bc4878 (patch)
treeab65fdb9caf32f92d1e058cf178d73b57aef786e /lib/libc/gen/ttyname.c
parentRegen. (diff)
downloadwireguard-openbsd-4eec04afc3730282d2e54e2ec3e899f7d7bc4878.tar.xz
wireguard-openbsd-4eec04afc3730282d2e54e2ec3e899f7d7bc4878.zip
make proper use of fstatat, as suggested by guenther@
okay millert@
Diffstat (limited to 'lib/libc/gen/ttyname.c')
-rw-r--r--lib/libc/gen/ttyname.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c
index 456fe798087..5efbc0d220f 100644
--- a/lib/libc/gen/ttyname.c
+++ b/lib/libc/gen/ttyname.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttyname.c,v 1.17 2016/06/27 06:10:04 espie Exp $ */
+/* $OpenBSD: ttyname.c,v 1.18 2016/06/27 16:52:30 espie Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -122,16 +122,14 @@ oldttyname(struct stat *sb, char *buf, size_t len)
while ((dirp = readdir(dp))) {
if (dirp->d_type != DT_CHR && dirp->d_type != DT_UNKNOWN)
continue;
- if (dirp->d_namlen > len - sizeof(_PATH_DEV)) {
- (void)closedir(dp);
+ if (fstatat(dirfd(dp), dirp->d_name, &dsb, AT_SYMLINK_NOFOLLOW)
+ || !S_ISCHR(dsb.st_mode) || sb->st_rdev != dsb.st_rdev)
+ continue;
+ (void)closedir(dp);
+ if (dirp->d_namlen > len - sizeof(_PATH_DEV))
return (ERANGE);
- }
memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name,
dirp->d_namlen + 1);
- if (lstat(buf, &dsb) || !S_ISCHR(dsb.st_mode) ||
- sb->st_rdev != dsb.st_rdev)
- continue;
- (void)closedir(dp);
return (0);
}
(void)closedir(dp);