]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
{commands,start}: remove element from list first
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 18 Feb 2018 22:20:05 +0000 (23:20 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 18 Feb 2018 22:20:05 +0000 (23:20 +0100)
First remove the client from the list then close the fd. Otherwise we open
ourselves to a race where another codepath might be writing to a bad file
descriptor.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c
src/lxc/start.c

index eae06d9beeed2456bbd30a0306ff19954a6061c8..277f87b234e2ebd6e6cc0939d54c8a09c452c4cf 100644 (file)
@@ -1156,8 +1156,8 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
                        continue;
 
                /* kick client from list */
-               close(client->clientfd);
                lxc_list_del(cur);
+               close(client->clientfd);
                free(cur->elem);
                free(cur);
                /* No need to walk the whole list. If we found the state client
index 228dd260744879d0dece8531d1cb499fca2ec4df..a0be7cdead753fcc443087c192b687a4411b971a 100644 (file)
@@ -427,8 +427,8 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
                }
 
                /* kick client from list */
-               close(client->clientfd);
                lxc_list_del(cur);
+               close(client->clientfd);
                free(cur->elem);
                free(cur);
        }