mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
CVE-2022-3592 lib: Move subdir_of() to source3/lib/util_path.c
Make it available for other components Bug: https://bugzilla.samba.org/show_bug.cgi?id=15207 Signed-off-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
parent
fbc0feeca4
commit
d905dbddf8
@ -304,3 +304,53 @@ bool extract_snapshot_token(char *fname, NTTIME *twrp)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Take two absolute paths, figure out if "subdir" is a proper
|
||||
* subdirectory of "parent". Return the component relative to the
|
||||
* "parent" without the potential "/". Take care of "parent"
|
||||
* possibly ending in "/".
|
||||
*/
|
||||
bool subdir_of(const char *parent,
|
||||
size_t parent_len,
|
||||
const char *subdir,
|
||||
const char **_relative)
|
||||
{
|
||||
const char *relative = NULL;
|
||||
bool matched;
|
||||
|
||||
SMB_ASSERT(parent[0] == '/');
|
||||
SMB_ASSERT(subdir[0] == '/');
|
||||
|
||||
if (parent_len == 1) {
|
||||
/*
|
||||
* Everything is below "/"
|
||||
*/
|
||||
*_relative = subdir+1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parent[parent_len-1] == '/') {
|
||||
parent_len -= 1;
|
||||
}
|
||||
|
||||
matched = (strncmp(subdir, parent, parent_len) == 0);
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
|
||||
relative = &subdir[parent_len];
|
||||
|
||||
if (relative[0] == '\0') {
|
||||
*_relative = relative; /* nothing left */
|
||||
return true;
|
||||
}
|
||||
|
||||
if (relative[0] == '/') {
|
||||
/* End of parent must match a '/' in subdir. */
|
||||
*_relative = relative+1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -49,5 +49,9 @@ bool clistr_is_previous_version_path(const char *path,
|
||||
const char **startp,
|
||||
const char **endp,
|
||||
NTTIME *ptwrp);
|
||||
bool subdir_of(const char *parent,
|
||||
size_t parent_len,
|
||||
const char *subdir,
|
||||
const char **_relative);
|
||||
|
||||
#endif
|
||||
|
@ -475,58 +475,6 @@ static NTSTATUS check_base_file_access(struct files_struct *fsp,
|
||||
access_mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* Take two absolute paths, figure out if "subdir" is a proper
|
||||
* subdirectory of "parent". Return the component relative to the
|
||||
* "parent" without the potential "/". Take care of "parent"
|
||||
* possibly ending in "/".
|
||||
*/
|
||||
static bool subdir_of(
|
||||
const char *parent,
|
||||
size_t parent_len,
|
||||
const char *subdir,
|
||||
const char **_relative)
|
||||
|
||||
{
|
||||
const char *relative = NULL;
|
||||
bool matched;
|
||||
|
||||
SMB_ASSERT(parent[0] == '/');
|
||||
SMB_ASSERT(subdir[0] == '/');
|
||||
|
||||
if (parent_len == 1) {
|
||||
/*
|
||||
* Everything is below "/"
|
||||
*/
|
||||
*_relative = subdir+1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parent[parent_len-1] == '/') {
|
||||
parent_len -= 1;
|
||||
}
|
||||
|
||||
matched = (strncmp(subdir, parent, parent_len) == 0);
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
|
||||
relative = &subdir[parent_len];
|
||||
|
||||
if (relative[0] == '\0') {
|
||||
*_relative = relative; /* nothing left */
|
||||
return true;
|
||||
}
|
||||
|
||||
if (relative[0] == '/') {
|
||||
/* End of parent must match a '/' in subdir. */
|
||||
*_relative = relative+1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static NTSTATUS chdir_below_conn(
|
||||
TALLOC_CTX *mem_ctx,
|
||||
connection_struct *conn,
|
||||
|
Loading…
Reference in New Issue
Block a user