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
This commit is contained in:
Bowgo Tsai 2017-09-26 18:03:23 +08:00
parent dea5e081ac
commit cc323958f9
1 changed files with 8 additions and 7 deletions

View File

@ -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;
}
/*