]> git.proxmox.com Git - mirror_lxc.git/commitdiff
close correct side of the pipe and increase buffer size by one to handle \n
authorS.Çağlar Onur <caglar@10ur.org>
Mon, 17 Feb 2014 20:08:18 +0000 (15:08 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 17 Feb 2014 22:26:06 +0000 (17:26 -0500)
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/conf.c

index 10f46aef15b207f25a6a979822d3f6be199fc686..175a82f8276198b3d1cac0ae8cc994b62efb3067 100644 (file)
@@ -3011,13 +3011,14 @@ void lxc_delete_network(struct lxc_handler *handler)
 
 #define LXC_USERNIC_PATH LIBEXECDIR "/lxc/lxc-user-nic"
 
+/* lxc-user-nic returns "interface_name:interface_name\n" */
+#define MAX_BUFFER_SIZE IFNAMSIZ*2 + 2
 static int unpriv_assign_nic(struct lxc_netdev *netdev, pid_t pid)
 {
        pid_t child;
        int bytes, pipefd[2];
        char *token, *saveptr = NULL;
-       /* lxc-user-nic returns "interface_name:interface_name" format */
-       char buffer[IFNAMSIZ*2 + 1];
+       char buffer[MAX_BUFFER_SIZE];
 
        if (netdev->type != LXC_NET_VETH) {
                ERROR("nic type %d not support for unprivileged use",
@@ -3043,7 +3044,7 @@ static int unpriv_assign_nic(struct lxc_netdev *netdev, pid_t pid)
                /* redirect the stdout to write-end of the pipe */
                dup2(pipefd[1], STDOUT_FILENO);
                /* close the write-end of the pipe */
-               close(pipefd[0]);
+               close(pipefd[1]);
 
                // Call lxc-user-nic pid type bridge
                char pidstr[20];
@@ -3058,7 +3059,7 @@ static int unpriv_assign_nic(struct lxc_netdev *netdev, pid_t pid)
        /* close the write-end of the pipe */
        close(pipefd[1]);
 
-       bytes = read(pipefd[0], &buffer, IFNAMSIZ*2 + 1);
+       bytes = read(pipefd[0], &buffer, MAX_BUFFER_SIZE);
        if (bytes < 0) {
                SYSERROR("read failed");
        }