The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/949

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
All uses of netlink_open() assume that on error the
nl_handler doesn't need to be closed, but some error cases
happen after the socket was opened successfully and used to
simply return -errno.
From a058b893fd5605cec1ab55c3c0b032e5ea4ab9c9 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumil...@proxmox.com>
Date: Wed, 6 Apr 2016 10:56:04 +0200
Subject: [PATCH] netlink_open: close socket on error

All uses of netlink_open() assume that on error the
nl_handler doesn't need to be closed, but some error cases
happen after the socket was opened successfully and used to
simply return -errno.
---
 src/lxc/nl.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/lxc/nl.c b/src/lxc/nl.c
index cfa5cdf..19a3a6c 100644
--- a/src/lxc/nl.c
+++ b/src/lxc/nl.c
@@ -265,6 +265,7 @@ extern int netlink_open(struct nl_handler *handler, int 
protocol)
        socklen_t socklen;
        int sndbuf = 32768;
        int rcvbuf = 32768;
+       int err;
 
        memset(handler, 0, sizeof(*handler));
 
@@ -274,11 +275,11 @@ extern int netlink_open(struct nl_handler *handler, int 
protocol)
 
        if (setsockopt(handler->fd, SOL_SOCKET, SO_SNDBUF,
                       &sndbuf, sizeof(sndbuf)) < 0)
-               return -errno;
+               goto err_with_errno;
 
        if (setsockopt(handler->fd, SOL_SOCKET, SO_RCVBUF,
                       &rcvbuf,sizeof(rcvbuf)) < 0)
-               return -errno;
+               goto err_with_errno;
 
        memset(&handler->local, 0, sizeof(handler->local));
        handler->local.nl_family = AF_NETLINK;
@@ -286,22 +287,31 @@ extern int netlink_open(struct nl_handler *handler, int 
protocol)
 
        if (bind(handler->fd, (struct sockaddr*)&handler->local,
                 sizeof(handler->local)) < 0)
-               return -errno;
+               goto err_with_errno;
 
        socklen = sizeof(handler->local);
        if (getsockname(handler->fd, (struct sockaddr*)&handler->local,
                        &socklen) < 0)
-               return -errno;
+               goto err_with_errno;
 
-       if (socklen != sizeof(handler->local))
-               return -EINVAL;
+       if (socklen != sizeof(handler->local)) {
+               err = -EINVAL;
+               goto errclose;
+       }
 
-       if (handler->local.nl_family != AF_NETLINK)
-               return -EINVAL;
+       if (handler->local.nl_family != AF_NETLINK) {
+               err = -EINVAL;
+               goto errclose;
+       }
 
        handler->seq = time(NULL);
 
        return 0;
+err_with_errno:
+       err = -errno;
+errclose:
+       close(handler->fd);
+       return err;
 }
 
 extern int netlink_close(struct nl_handler *handler)
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to