Author: seanc (ports committer)
Date: Fri Jul 12 18:50:46 2019
New Revision: 349952
URL: https://svnweb.freebsd.org/changeset/base/349952

Log:
  usr.sbin/bhyve: close backend file descriptor during tap init error
  
  Coverity CID: 1402953
  Reviewed by:  scottl, markj, aleksandr.fedorov -at- itglobal.com
  Approved by:  vmaffione, jhb
  Differential Revision:        https://reviews.freebsd.org/D20913

Modified:
  head/usr.sbin/bhyve/net_backends.c

Modified: head/usr.sbin/bhyve/net_backends.c
==============================================================================
--- head/usr.sbin/bhyve/net_backends.c  Fri Jul 12 18:43:24 2019        
(r349951)
+++ head/usr.sbin/bhyve/net_backends.c  Fri Jul 12 18:50:46 2019        
(r349952)
@@ -175,7 +175,6 @@ tap_init(struct net_backend *be, const char *devname,
 {
        struct tap_priv *priv = (struct tap_priv *)be->opaque;
        char tbuf[80];
-       int fd;
        int opt = 1;
 #ifndef WITHOUT_CAPSICUM
        cap_rights_t rights;
@@ -189,8 +188,8 @@ tap_init(struct net_backend *be, const char *devname,
        strcpy(tbuf, "/dev/");
        strlcat(tbuf, devname, sizeof(tbuf));
 
-       fd = open(tbuf, O_RDWR);
-       if (fd == -1) {
+       be->fd = open(tbuf, O_RDWR);
+       if (be->fd == -1) {
                WPRINTF(("open of tap device %s failed\n", tbuf));
                goto error;
        }
@@ -199,24 +198,22 @@ tap_init(struct net_backend *be, const char *devname,
         * Set non-blocking and register for read
         * notifications with the event loop
         */
-       if (ioctl(fd, FIONBIO, &opt) < 0) {
+       if (ioctl(be->fd, FIONBIO, &opt) < 0) {
                WPRINTF(("tap device O_NONBLOCK failed\n"));
                goto error;
        }
 
 #ifndef WITHOUT_CAPSICUM
        cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
-       if (caph_rights_limit(fd, &rights) == -1)
+       if (caph_rights_limit(be->fd, &rights) == -1)
                errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
-       priv->mevp = mevent_add(fd, EVF_READ, cb, param);
+       priv->mevp = mevent_add(be->fd, EVF_READ, cb, param);
        if (priv->mevp == NULL) {
                WPRINTF(("Could not register event\n"));
                goto error;
        }
-
-       be->fd = fd;
 
        return (0);
 
_______________________________________________
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