Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #876, break up logic in return statement #900

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,26 @@ bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, co
}

mplen = OS_strnlen(filesys->virtual_mountpt, sizeof(filesys->virtual_mountpt));
return (mplen > 0 && mplen < sizeof(filesys->virtual_mountpt) &&
strncmp(target, filesys->virtual_mountpt, mplen) == 0 && (target[mplen] == '/' || target[mplen] == 0));

/*
* The virtual_mountpt member should be a substring of the search target.
* If this matches a basic substring check then it may be match
*/
if (mplen == 0 || mplen >= sizeof(filesys->virtual_mountpt) ||
strncmp(target, filesys->virtual_mountpt, mplen) != 0)
{
/* not a substring, so not a match */
return false;
}

/*
* Confirm that the substring ends at either a directory separator
* or the end of string (so exact mount points also match).
*
* For instance consider a virtual_mountpt of /mnt/abc and searching
* for target=/mnt/abcd - this should return false in that case.
*/
return (target[mplen] == '/' || target[mplen] == 0);
} /* end OS_FileSys_FindVirtMountPoint */

/*----------------------------------------------------------------
Expand Down