about summary refs log tree commit diff
path: root/src/unistd
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-07-09 00:42:09 -0400
committerRich Felker <dalias@aerifal.cx>2013-07-09 00:42:09 -0400
commitcdf0f53f8ba0e79dedb83c626851597bacec53ca (patch)
tree8873f981fc2c5ab9d75b8b3a7c8ea2006fb1cb67 /src/unistd
parent0716b10ac8dc167f96969c964974d4094035fed0 (diff)
downloadmusl-cdf0f53f8ba0e79dedb83c626851597bacec53ca.tar.gz
musl-cdf0f53f8ba0e79dedb83c626851597bacec53ca.tar.xz
musl-cdf0f53f8ba0e79dedb83c626851597bacec53ca.zip
fix fd leak on races and cancellation in ctermid
Diffstat (limited to 'src/unistd')
-rw-r--r--src/unistd/ctermid.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/unistd/ctermid.c b/src/unistd/ctermid.c
index 21b44ec8..c238905a 100644
--- a/src/unistd/ctermid.c
+++ b/src/unistd/ctermid.c
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <limits.h>
+#include "syscall.h"
 
 char *ctermid(char *s)
 {
@@ -13,11 +14,11 @@ char *ctermid(char *s)
 		if (!s2) s2 = malloc(L_ctermid);
 		s = s2;
 	}
-	fd = open("/dev/tty", O_WRONLY | O_NOCTTY);
+	fd = open("/dev/tty", O_WRONLY | O_NOCTTY | O_CLOEXEC);
 	if (fd < 0)
 		return strcpy(s, "");
 	if (ttyname_r(fd, s, L_ctermid))
 		strcpy(s, "");
-	close(fd);
+	__syscall(SYS_close, fd);
 	return s;
 }