Skip to content

Commit

Permalink
{commands,start}: remove element from list first
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christian Brauner committed Feb 21, 2018
1 parent 96f0cf3 commit 7669dc3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lxc/commands.c
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/start.c
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7669dc3

Please sign in to comment.