Commit
c96c22f1d94 "mini-os: minimal implementations of some termios
functions" introduced implementations of tcgetattr and tcsetattr.
However, they do not check if files[fildes].cons.dev is non-NULL before
dereferencing. This is not a problem for FDs allocated through
alloc_fd, but the files array pre-allocates FDs 0-2 for stdio. Those
entries have a NULL .dev, so tc{g,s}etattr on them segfault.
ioemu-stubdom segfaults when term_init() calls tcgetattr on FD 0.
Restore tcgetattr and tcsetattr behavior when .dev is NULL equivalent to
unsupported_function as it was before
c96c22f1d94.
Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
return -1;
}
+ if (files[fildes].cons.dev == NULL) {
+ errno = ENOSYS;
+ return -1;
+ }
+
if (tios->c_oflag & OPOST)
files[fildes].cons.dev->is_raw = false;
else
return -1;
}
+ if (files[fildes].cons.dev == NULL) {
+ errno = ENOSYS;
+ return 0;
+ }
+
if (tios == NULL) {
errno = EINVAL;
return -1;