From 997adc7e61a4a3b0715f0aa59288b5b22f4b7e61 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 29 Apr 2023 20:01:08 -0400 Subject: [PATCH] kernel/fd: Add missing NULL checks in user_io routines. I am not sure how this path could be hit besides having O_APPEND set on a socket, which appears to be possible, though I don't know what purpose that would serve. Tested by adding these two lines between the sleep() and close() in the in-tree tcp_connection_test: fcntl(fd, F_SETFL, O_APPEND); write(fd, "Hello", 5); Before this commit, the above lines cause a KDL. May fix #18133, but I don't presently have access to the reproduction setup described in that ticket. --- src/system/kernel/fs/fd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/fs/fd.cpp b/src/system/kernel/fs/fd.cpp index 28034a8e25..d63531bac9 100644 --- a/src/system/kernel/fs/fd.cpp +++ b/src/system/kernel/fs/fd.cpp @@ -747,7 +747,7 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write) } bool movePosition = false; - if (pos == -1) { + if (pos == -1 && descriptor->ops->fd_seek != NULL) { pos = descriptor->pos; movePosition = true; } @@ -806,7 +806,7 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count, } bool movePosition = false; - if (pos == -1) { + if (pos == -1 && descriptor->ops->fd_seek != NULL) { pos = descriptor->pos; movePosition = true; }