|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [mini-os master] mini-os: Avoid segfaults in tc{g,s}etattr
commit f82b8134cbcbcca91ff325aaf4200ee55b7e2d7a
Author: Jason Andryuk <jandryuk@xxxxxxxxx>
AuthorDate: Sun Apr 26 23:40:19 2020 -0400
Commit: Wei Liu <wl@xxxxxxx>
CommitDate: Tue Apr 28 12:18:14 2020 +0100
mini-os: Avoid segfaults in tc{g,s}etattr
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@xxxxxxxxx>
Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
---
lib/sys.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/sys.c b/lib/sys.c
index da434fc..c6a7b9f 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -1472,6 +1472,11 @@ int tcsetattr(int fildes, int action, const struct
termios *tios)
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
@@ -1492,6 +1497,11 @@ int tcgetattr(int fildes, struct termios *tios)
return -1;
}
+ if (files[fildes].cons.dev == NULL) {
+ errno = ENOSYS;
+ return 0;
+ }
+
if (tios == NULL) {
errno = EINVAL;
return -1;
--
generated by git-patchbot for /home/xen/git/mini-os.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |