Author: trasz
Date: Sun Feb  5 14:03:25 2017
New Revision: 313283
URL: https://svnweb.freebsd.org/changeset/base/313283

Log:
  Fix linux_pipe() and linux_pipe2() to close file descriptors on copyout
  error.
  
  Reviewed by:  dchagin
  MFC after:    2 weeks
  Sponsored by: DARPA, AFRL
  Differential Revision:        https://reviews.freebsd.org/D9425

Modified:
  head/sys/compat/linux/linux_file.c

Modified: head/sys/compat/linux/linux_file.c
==============================================================================
--- head/sys/compat/linux/linux_file.c  Sun Feb  5 13:37:23 2017        
(r313282)
+++ head/sys/compat/linux/linux_file.c  Sun Feb  5 14:03:25 2017        
(r313283)
@@ -1537,11 +1537,16 @@ linux_pipe(struct thread *td, struct lin
 #endif
 
        error = kern_pipe(td, fildes, 0, NULL, NULL);
-       if (error)
+       if (error != 0)
                return (error);
 
-       /* XXX: Close descriptors on error. */
-       return (copyout(fildes, args->pipefds, sizeof(fildes)));
+       error = copyout(fildes, args->pipefds, sizeof(fildes));
+       if (error != 0) {
+               (void)kern_close(td, fildes[0]);
+               (void)kern_close(td, fildes[1]);
+       }
+
+       return (error);
 }
 
 int
@@ -1564,11 +1569,16 @@ linux_pipe2(struct thread *td, struct li
        if ((args->flags & LINUX_O_CLOEXEC) != 0)
                flags |= O_CLOEXEC;
        error = kern_pipe(td, fildes, flags, NULL, NULL);
-       if (error)
+       if (error != 0)
                return (error);
 
-       /* XXX: Close descriptors on error. */
-       return (copyout(fildes, args->pipefds, sizeof(fildes)));
+       error = copyout(fildes, args->pipefds, sizeof(fildes));
+       if (error != 0) {
+               (void)kern_close(td, fildes[0]);
+               (void)kern_close(td, fildes[1]);
+       }
+
+       return (error);
 }
 
 int
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to