diff options
author | dzwdz | 2021-08-27 19:36:37 +0200 |
---|---|---|
committer | dzwdz | 2021-08-27 19:36:37 +0200 |
commit | a5bd09d5a995400c4f4ec1270e1ad380d238783c (patch) | |
tree | 7feffaf5ad13308a792481a77fa868cbd58b7917 /src/kernel | |
parent | aa3ce9383da78a83b64160d5c64ecd077d0b36ef (diff) |
make vfs_mount_resolve pass all the tests
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/tests/vfs.c | 8 | ||||
-rw-r--r-- | src/kernel/vfs/mount.c | 11 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c index cfbf86b..0871f92 100644 --- a/src/kernel/tests/vfs.c +++ b/src/kernel/tests/vfs.c @@ -70,7 +70,7 @@ TEST(vfs_mount_resolve) { mount = mount2; \ } while (0) - ADD_MOUNT("/"); + ADD_MOUNT(""); // root mount ADD_MOUNT("/dir/shadowed"); ADD_MOUNT("/dir"); @@ -82,10 +82,10 @@ TEST(vfs_mount_resolve) { && (0 == memcmp(mount2->prefix, expected, mount2->prefix_len))); \ } while (0) - TEST_WRAPPER("/", "/"); - TEST_WRAPPER("/test", "/"); + TEST_WRAPPER("/", ""); + TEST_WRAPPER("/test", ""); TEST_WRAPPER("/dir", "/dir"); - TEST_WRAPPER("/dirry", "/"); + TEST_WRAPPER("/dirry", ""); TEST_WRAPPER("/dir/", "/dir"); TEST_WRAPPER("/dir/shadowed", "/dir"); TEST_WRAPPER("/dir/shadowed/", "/dir"); diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c index bf98957..bd06370 100644 --- a/src/kernel/vfs/mount.c +++ b/src/kernel/vfs/mount.c @@ -21,7 +21,16 @@ struct vfs_mount *vfs_mount_resolve( for (; top; top = top->prev) { if (top->prefix_len > path_len) continue; - if (memcmp(top->prefix, path, top->prefix_len) == 0) + if (memcmp(top->prefix, path, top->prefix_len) != 0) + continue; + + /* ensure that there's no garbage after the match + * recognize that e.g. /thisasdf doesn't get recognized as mounted under + * /this */ + + if (top->prefix_len == path_len) // can't happen if prefix == path + break; + if (path[top->prefix_len] == '/') break; } return top; |