Skip to content

Commit 37ef31e

Browse files
CopilotJohnAmadis
andcommitted
Add boundary checking to prevent incorrect prefix matches
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 3e222f0 commit 37ef31e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/dmvfs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,16 @@ static mount_point_t* get_mount_point_for_path(const char* path)
344344
if(g_mount_points[i].mount_point != NULL)
345345
{
346346
size_t mount_point_length = strlen(g_mount_points[i].mount_point);
347+
// Check if path starts with mount point and either:
348+
// - The mount point is the root "/" (special case - matches all paths)
349+
// - The mount point is exactly the path (path[mount_point_length] == '\0')
350+
// - The next character is a path separator (path[mount_point_length] == '/')
351+
// This ensures we match at path boundaries only
352+
bool is_root_mount = (mount_point_length == 1 && g_mount_points[i].mount_point[0] == '/');
353+
bool is_boundary_match = (path[mount_point_length] == '/' || path[mount_point_length] == '\0');
354+
347355
if(strncmp(path, g_mount_points[i].mount_point, mount_point_length) == 0 &&
356+
(is_root_mount || is_boundary_match) &&
348357
mount_point_length > best_match_length)
349358
{
350359
best_match = &g_mount_points[i];

tests/test_mount_point_selection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
2828
if (argc < 3) {
2929
printf("Usage: %s <fs1_module.dmf> <fs2_module.dmf>\n", argv[0]);
3030
printf("This test requires two filesystem modules to test mount point selection.\n");
31-
return 1;
31+
return -1;
3232
}
3333

3434
const char* fs1_path = argv[1];

0 commit comments

Comments
 (0)