diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2015-06-23 07:12:08 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2015-06-26 23:09:42 -0400 |
commit | 8481e3d3f84153184492af64627d21f391587c61 (patch) | |
tree | 292bc79e5be93978dec30a04d57b088bd13c1a84 /ext | |
parent | 6e7b1a261d86fa4754e5d9ee167b6679abdc1cb2 (diff) | |
download | perl-8481e3d3f84153184492af64627d21f391587c61.tar.gz |
tcsetattr fd can be bad.
Coverity CID 104815
Diffstat (limited to 'ext')
-rw-r--r-- | ext/POSIX/POSIX.xs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index bd13d52f6b..ba986bb8f0 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -1953,11 +1953,16 @@ setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION) int fd int optional_actions CODE: - /* The second argument to the call is mandatory, but we'd like to give - it a useful default. 0 isn't valid on all operating systems - on - Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same - values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */ - RETVAL = tcsetattr(fd, optional_actions, termios_ref); + if (fd >= 0) { + /* The second argument to the call is mandatory, but we'd like to give + it a useful default. 0 isn't valid on all operating systems - on + Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same + values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */ + RETVAL = tcsetattr(fd, optional_actions, termios_ref); + } else { + SETERRNO(EBADF,RMS_IFI); + RETVAL = -1; + } OUTPUT: RETVAL |