diff options
| author | Rich Felker <dalias@aerifal.cx> | 2013-07-09 00:42:09 -0400 | 
|---|---|---|
| committer | Rich Felker <dalias@aerifal.cx> | 2013-07-09 00:42:09 -0400 | 
| commit | cdf0f53f8ba0e79dedb83c626851597bacec53ca (patch) | |
| tree | 8873f981fc2c5ab9d75b8b3a7c8ea2006fb1cb67 /src | |
| parent | 0716b10ac8dc167f96969c964974d4094035fed0 (diff) | |
| download | musl-cdf0f53f8ba0e79dedb83c626851597bacec53ca.tar.gz | |
fix fd leak on races and cancellation in ctermid
Diffstat (limited to 'src')
| -rw-r--r-- | src/unistd/ctermid.c | 5 | 
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;  } | 
