summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authordzwdz2024-05-11 20:41:00 +0200
committerdzwdz2024-05-11 20:41:00 +0200
commite4ebea27b2f339706da76a3e79cb63ea9ed97c38 (patch)
tree4cb8e90a512fd68c0e0412dc8da58ec7f312e026 /src/cmd
parent9047f1e3f502658de12808015179ab3881a4b03f (diff)
kernel: fix null dereference when delegating an nonexistent handle
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/tests/kernel/fs.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/cmd/tests/kernel/fs.c b/src/cmd/tests/kernel/fs.c
index 449ed43..6d4f4f4 100644
--- a/src/cmd/tests/kernel/fs.c
+++ b/src/cmd/tests/kernel/fs.c
@@ -77,9 +77,32 @@ static void test_no_fs(void) {
test(_sys_fs_wait(buf, 256, &res) == -EPIPE);
}
+/* Tries to delegate a nonexistent handle */
+static void test_bad_delegate(void) {
+ hid_t h = -1;
+ int ret = _sys_fork(FORK_NEWFS, &h);
+ test(0 <= ret);
+ if (ret == 0) {
+ struct ufs_request res;
+ for (;;) {
+ h = _sys_fs_wait(NULL, 0, &res);
+ _sys_close(0);
+ _sys_fs_respond(h, NULL, 0, FSR_DELEGATE);
+ }
+ } else {
+ test(0 <= h);
+ test(_sys_mount(h, "/", 1) == 0);
+ for (int i = 0; i < 4; i++) {
+ int ret = _sys_open("/", 1, 0);
+ test(ret < 0);
+ }
+ }
+}
+
void r_k_fs(void) {
run_test(test_unfinished_req);
run_test(test_orphaned_fs);
run_test(test_fs_cleanup);
run_test(test_no_fs);
+ run_test(test_bad_delegate);
}