]> git.proxmox.com Git - mirror_lxc.git/commitdiff
conf: safely retrieve path of slave device
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 4 Jul 2018 12:51:48 +0000 (14:51 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 4 Jul 2018 16:21:36 +0000 (18:21 +0200)
openpty() is a horrible function that uses strcpy() into the char *name
argument if name != NULL. We can't rely on the path being sane in all cases so
let's split out the name retrieval to ttyname_r().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 8ba5fa8339006a423421ef21f206a64396d902fb..0f02e400c568d7eaeff2ddcad386ad79054b880a 100644 (file)
@@ -971,15 +971,22 @@ int lxc_allocate_ttys(struct lxc_conf *conf)
 
                tty->master = -EBADF;
                tty->slave = -EBADF;
-               ret = openpty(&tty->master, &tty->slave,
-                             tty->name, NULL, NULL);
-               if (ret) {
+               ret = openpty(&tty->master, &tty->slave, NULL, NULL, NULL);
+               if (ret < 0) {
                        SYSERROR("Failed to create tty %d", i);
                        ttys->max = i;
                        lxc_delete_tty(ttys);
                        return -ENOTTY;
                }
 
+               ret = ttyname_r(tty->slave, tty->name, sizeof(tty->name));
+               if (ret < 0) {
+                       SYSERROR("Failed to retrieve name of tty %d slave", i);
+                       ttys->max = i;
+                       lxc_delete_tty(ttys);
+                       return -ENOTTY;
+               }
+
                DEBUG("Created tty \"%s\" with master fd %d and slave fd %d",
                      tty->name, tty->master, tty->slave);