Message ID | 20190114133024.18320-1-fdmanana@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/3] Btrfs-progs: fix mount point detection due to partial prefix match | expand |
On Mon, 14 Jan 2019 13:30:24 +0000, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > > When attempting to find the mount point of a path we can end up returning > an incorrect mount point. This happens because we consider a mount point > valid for the given path even if it matches only partially the patch. s/patch/path/? "...even if it only partially matches" might be a bit clearer. > diff --git a/utils.c b/utils.c > index 3a4bc92a..6616630b 100644 > --- a/utils.c > +++ b/utils.c > @@ -2064,7 +2064,8 @@ int find_mount_root(const char *path, char **mount_root) > > while ((ent = getmntent(mnttab))) { > len = strlen(ent->mnt_dir); > - if (strncmp(ent->mnt_dir, path, len) == 0) { > + if (strncmp(ent->mnt_dir, path, len) == 0 && > + (path[len] == '/' || path[len] == '\0')) { Looks good and works for me. Reviewed-by: David Disseldorp <ddiss@suse.de>
On Mon, Jan 14, 2019 at 1:59 PM David Disseldorp <ddiss@suse.de> wrote: > > On Mon, 14 Jan 2019 13:30:24 +0000, fdmanana@kernel.org wrote: > > > From: Filipe Manana <fdmanana@suse.com> > > > > When attempting to find the mount point of a path we can end up returning > > an incorrect mount point. This happens because we consider a mount point > > valid for the given path even if it matches only partially the patch. > > s/patch/path/? "...even if it only partially matches" might be a bit > clearer. Agreed. David can probably correct that (and your email address from ddis@ to ddiss@) when he picks the patch, otherwise I can send a new version. Thanks. > > > diff --git a/utils.c b/utils.c > > index 3a4bc92a..6616630b 100644 > > --- a/utils.c > > +++ b/utils.c > > @@ -2064,7 +2064,8 @@ int find_mount_root(const char *path, char **mount_root) > > > > while ((ent = getmntent(mnttab))) { > > len = strlen(ent->mnt_dir); > > - if (strncmp(ent->mnt_dir, path, len) == 0) { > > + if (strncmp(ent->mnt_dir, path, len) == 0 && > > + (path[len] == '/' || path[len] == '\0')) { > > Looks good and works for me. > Reviewed-by: David Disseldorp <ddiss@suse.de>
diff --git a/utils.c b/utils.c index 3a4bc92a..6616630b 100644 --- a/utils.c +++ b/utils.c @@ -2064,7 +2064,8 @@ int find_mount_root(const char *path, char **mount_root) while ((ent = getmntent(mnttab))) { len = strlen(ent->mnt_dir); - if (strncmp(ent->mnt_dir, path, len) == 0) { + if (strncmp(ent->mnt_dir, path, len) == 0 && + (path[len] == '/' || path[len] == '\0')) { /* match found and use the latest match */ if (longest_matchlen <= len) { free(longest_match);