From cc323958f99e40fea06c511656c69c0b2e2d47f7 Mon Sep 17 00:00:00 2001 From: Bowgo Tsai Date: Tue, 26 Sep 2017 18:03:23 +0800 Subject: [PATCH] fs_mgr_fstab: do an exact match when searching a mount point Currently when searching a mount point from a fstab, it checks whether the mount point of an fstab entry is the prefix of a given path, and the next char after the match is either '\0' or '/'. However, it will always return the fstab entry with mount point "/vendor" when searching path is "/vendor", "/vendor/abc" or "/vendor/cde" in the following fstab. Because "/vendor" is the prefix of "/vendor/abc" and "/vendor/cde", and the next char after the match is '/'. /dev/block/platform/.../by-name/vendor /vendor ext4 ro wait /dev/block/platform/.../by-name/abc /vendor/abc ext4 ro wait /dev/block/platform/.../by-name/cde /vendor/cde ext4 ro wait Fix this by performing an exact match when searching the mount point. Bug: 63912287 Test: boot sailfish Change-Id: I504655f5c71790c5d528085de416ce3c30d21fea --- fs_mgr/fs_mgr_fstab.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index 41a58683e..31c880361 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -782,11 +782,12 @@ int fs_mgr_add_entry(struct fstab *fstab, * Returns the 1st matching fstab_rec that follows the start_rec. * start_rec is the result of a previous search or NULL. */ -struct fstab_rec *fs_mgr_get_entry_for_mount_point_after(struct fstab_rec *start_rec, struct fstab *fstab, const char *path) -{ +struct fstab_rec* fs_mgr_get_entry_for_mount_point_after(struct fstab_rec* start_rec, + struct fstab* fstab, + const std::string& path) { int i; if (!fstab) { - return NULL; + return nullptr; } if (start_rec) { @@ -799,14 +800,14 @@ struct fstab_rec *fs_mgr_get_entry_for_mount_point_after(struct fstab_rec *start } else { i = 0; } + for (; i < fstab->num_entries; i++) { - int len = strlen(fstab->recs[i].mount_point); - if (strncmp(path, fstab->recs[i].mount_point, len) == 0 && - (path[len] == '\0' || path[len] == '/')) { + if (fstab->recs[i].mount_point && path == fstab->recs[i].mount_point) { return &fstab->recs[i]; } } - return NULL; + + return nullptr; } /*