This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tcsetattr fd can be bad.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 23 Jun 2015 11:12:08 +0000 (07:12 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 27 Jun 2015 03:09:42 +0000 (23:09 -0400)
Coverity CID 104815

ext/POSIX/POSIX.xs

index bd13d52..ba986bb 100644 (file)
@@ -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