[CRIU] [PATCH] tty: don't crash if restoring a non-pty

Tycho Andersen tycho.andersen at canonical.com
Wed Oct 29 13:44:55 PDT 2014


The pty field here is only present with certain tty types, so we shouldn't
unconditionally dereference it, or criu will hang.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 tty.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tty.c b/tty.c
index 10c46d9..7d5f73a 100644
--- a/tty.c
+++ b/tty.c
@@ -486,7 +486,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
 {
 	struct tty_info *info = container_of(d, struct tty_info, d);
 	struct reg_file_info *fake = NULL;
-	int slave = -1, ret = -1;
+	int slave = -1, ret = -1, index;
 
 	if (!is_service_fd(fd, CTL_TTY_OFF))
 		return 0;
@@ -496,12 +496,14 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
 		if (!fake)
 			goto err;
 		slave = open_pty_reg(&fake->d, O_RDONLY);
+		index = info->tie->pty->index;
 		if (slave < 0) {
 			pr_perror("Can't open %s", path_from_reg(&fake->d));
 			goto err;
 		}
 	} else if (info->type == TTY_TYPE_CONSOLE) {
 		slave = open_pty_reg(info->reg_d, O_RDONLY);
+		index = -1;
 		if (slave < 0) {
 			pr_perror("Can't open %s", path_from_reg(info->reg_d));
 			goto err;
@@ -510,8 +512,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
 		BUG();
 
 	pr_info("Restore session %d by %d tty (index %d)\n",
-		 info->tie->sid, (int)getpid(),
-		 info->tie->pty->index);
+		 info->tie->sid, (int)getpid(), index);
 
 	ret = tty_set_sid(slave);
 	if (!ret)
-- 
2.1.0



More information about the CRIU mailing list