conf: safely retrieve path of slave device

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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 615f24ff
...@@ -971,15 +971,22 @@ int lxc_allocate_ttys(struct lxc_conf *conf) ...@@ -971,15 +971,22 @@ int lxc_allocate_ttys(struct lxc_conf *conf)
tty->master = -EBADF; tty->master = -EBADF;
tty->slave = -EBADF; tty->slave = -EBADF;
ret = openpty(&tty->master, &tty->slave, ret = openpty(&tty->master, &tty->slave, NULL, NULL, NULL);
tty->name, NULL, NULL); if (ret < 0) {
if (ret) {
SYSERROR("Failed to create tty %d", i); SYSERROR("Failed to create tty %d", i);
ttys->max = i; ttys->max = i;
lxc_delete_tty(ttys); lxc_delete_tty(ttys);
return -ENOTTY; 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", DEBUG("Created tty \"%s\" with master fd %d and slave fd %d",
tty->name, tty->master, tty->slave); tty->name, tty->master, tty->slave);
......
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