Linux: correct mount point prefix checks

Excluding "/boot" mount point would also exclude directories
beginning with boot, without being a sub-directory.

Resolve by adding a version of STRPREFIX that delimits on null
terminator or slash.
This commit is contained in:
Campbell Barton
2025-04-12 02:09:18 +00:00
parent 3b2c0b6cd5
commit 219e6aa6d6

View File

@@ -580,17 +580,28 @@ void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
fprintf(stderr, "could not get a list of mounted file-systems\n");
}
else {
/* Similar to `STRPREFIX`,
* but ensures the prefix precedes a directory separator or null terminator.
* Define locally since it's fairly specific to this particular use case. */
auto strncmp_dir_delimit = [](const char *a, const char *b, size_t b_len) -> int {
const int result = strncmp(a, b, b_len);
return (result == 0 && !ELEM(a[b_len], '\0', '/')) ? 1 : result;
};
# define STRPREFIX_DIR_DELIMIT(a, b) (strncmp_dir_delimit((a), (b), strlen(b)) == 0)
while ((mnt = getmntent(fp))) {
if (STRPREFIX(mnt->mnt_dir, "/boot")) {
if (STRPREFIX_DIR_DELIMIT(mnt->mnt_dir, "/boot")) {
/* Hide share not usable to the user. */
continue;
}
if (!STRPREFIX(mnt->mnt_fsname, "/dev")) {
if (!STRPREFIX_DIR_DELIMIT(mnt->mnt_fsname, "/dev")) {
continue;
}
/* Use non-delimited prefix since a slash isn't expected after loop. */
if (STRPREFIX(mnt->mnt_fsname, "/dev/loop")) {
/* The dev/loop* entries are SNAPS used by desktop environment
* (Gnome) no need for them to show up in the list. */
/* The `/dev/loop*` entries are SNAPS used by desktop environment
* (GNOME) no need for them to show up in the list. */
continue;
}
@@ -603,6 +614,8 @@ void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
found = 1;
}
# undef STRPREFIX_DIR_DELIMIT
if (endmntent(fp) == 0) {
fprintf(stderr, "could not close the list of mounted file-systems\n");
}