]> 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>
Wed, 21 Feb 2018 16:59:41 +0000 (17:59 +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 8f241d461b9d5a0ea0f22e594df69f308fe2a40a..302fc40122fc443e877a7a9f8a319f9cd5397248 100644 (file)
@@ -1021,8 +1021,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 b31747dc9624c8eb38b6752a30e230c292a0e4e0..a24c93f355f4c87c8c98b2c936b75a187cc9404b 100644 (file)
@@ -418,8 +418,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);
        }