From 0b78de8e0f81d494eed3a617cec6c1fa0cbbd963 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 14 Jun 2010 15:06:39 -0400 Subject: [PATCH] Call selinux_restore_tty() as part of cleanup() so it gets called from error()/errorx() --HG-- branch : 1.7 --- selinux.c | 10 +++++++--- sudo.c | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/selinux.c b/selinux.c index a423aa9c7..de3c43eeb 100644 --- a/selinux.c +++ b/selinux.c @@ -66,7 +66,6 @@ static struct selinux_state { * * Returns zero on success, non-zero otherwise */ -/* XXX - should also be called as part of cleanup() */ int selinux_restore_tty(void) { @@ -91,9 +90,14 @@ selinux_restore_tty(void) warning("unable to restore context for %s", se_state.ttyn); skip_relabel: - if (se_state.ttyfd != -1) + if (se_state.ttyfd != -1) { close(se_state.ttyfd); - freecon(chk_tty_context); + se_state.ttyfd = -1; + } + if (chk_tty_context != NULL) { + freecon(chk_tty_context); + chk_tty_context = NULL; + } return retval; } diff --git a/sudo.c b/sudo.c index 6cbb198cc..c54f6a22d 100644 --- a/sudo.c +++ b/sudo.c @@ -1293,6 +1293,9 @@ cleanup(gotsignal) #endif } term_restore(STDIN_FILENO, 0); +#ifdef HAVE_SELINUX + selinux_restore_tty(); +#endif } static void -- 2.40.0