Unverified Commit 4226b2e5 by Christian Brauner Committed by GitHub

Merge pull request #3532 from alliedtelesis/fix_lxc_attach_crash

avoid a NULL pointer dereference in lxc-attach
parents 9cc837ef c3941f32
......@@ -1384,8 +1384,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
if (pid == 0) {
if (options->attach_flags & LXC_ATTACH_TERMINAL) {
ret = pthread_sigmask(SIG_SETMASK,
&terminal.tty_state->oldmask, NULL);
ret = lxc_terminal_signal_sigmask_safe_blocked(&terminal);
if (ret < 0) {
SYSERROR("Failed to reset signal mask");
_exit(EXIT_FAILURE);
......
......@@ -147,6 +147,16 @@ struct lxc_terminal_state *lxc_terminal_signal_init(int srcfd, int dstfd)
return move_ptr(ts);
}
int lxc_terminal_signal_sigmask_safe_blocked(struct lxc_terminal *terminal)
{
struct lxc_terminal_state *state = terminal->tty_state;
if (!state)
return 0;
return pthread_sigmask(SIG_SETMASK, &state->oldmask, NULL);
}
/**
* lxc_terminal_signal_fini: uninstall signal handler
*
......
......@@ -251,5 +251,6 @@ __hidden extern int lxc_terminal_prepare_login(int fd);
__hidden extern void lxc_terminal_conf_free(struct lxc_terminal *terminal);
__hidden extern void lxc_terminal_info_init(struct lxc_terminal_info *terminal);
__hidden extern void lxc_terminal_init(struct lxc_terminal *terminal);
__hidden extern int lxc_terminal_signal_sigmask_safe_blocked(struct lxc_terminal *terminal);
#endif /* __LXC_TERMINAL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment