[PATCH] Fix failure to update dirpath
Jeremy Allison
jra at samba.org
Mon Aug 20 23:37:27 UTC 2018
On Tue, Aug 21, 2018 at 04:51:38AM +0530, Anoop C S wrote:
>
> To be more precise, parent_dirname() inside check_parent_exists() correctly puts "." into *parent
> (which is nothing but parent_fname.base_name). It is just that we did not copy that over to
> *pp_dirpath before returning from check_parent_exists().
OK, I think this is the correct fix. Can you confirm it works
with your setup and I'll submit for review ?
Thanks,
Jeremy.
-------------- next part --------------
diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 9e15af1916d..39b570fc109 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -164,11 +164,10 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
char **pp_dirpath,
char **pp_start)
{
- struct smb_filename parent_fname;
+ struct smb_filename parent_fname = { 0 };
const char *last_component = NULL;
NTSTATUS status;
int ret;
- bool parent_fname_has_wild = false;
ZERO_STRUCT(parent_fname);
if (!parent_dirname(ctx, smb_fname->base_name,
@@ -178,18 +177,18 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
}
if (!posix_pathnames) {
- parent_fname_has_wild = ms_has_wild(parent_fname.base_name);
+ if (ms_has_wild(parent_fname.base_name)) {
+ goto no_optimization_out;
+ }
}
/*
* If there was no parent component in
- * smb_fname->base_name of the parent name
- * contained a wildcard then don't do this
+ * smb_fname->base_name then don't do this
* optimization.
*/
- if ((smb_fname->base_name == last_component) ||
- parent_fname_has_wild) {
- return NT_STATUS_OK;
+ if (smb_fname->base_name == last_component) {
+ goto no_optimization_out;
}
if (posix_pathnames) {
@@ -202,7 +201,7 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
with the normal tree walk. */
if (ret == -1) {
- return NT_STATUS_OK;
+ goto no_optimization_out;
}
status = check_for_dot_component(&parent_fname);
@@ -235,6 +234,28 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
*pp_start));
return NT_STATUS_OK;
+
+ no_optimization_out:
+
+ /*
+ * We must still return an *pp_dirpath
+ * initialized to ".", and a *pp_start
+ * pointing at smb_fname->base_name.
+ */
+
+ TALLOC_FREE(parent_fname.base_name);
+
+ *pp_dirpath = talloc_strdup(ctx, ".");
+ if (*pp_dirpath == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ /*
+ * Safe to use discard_const_p
+ * here as by convention smb_fname->base_name
+ * is allocated off ctx.
+ */
+ *pp_start = discard_const_p(char, smb_fname->base_name);
+ return NT_STATUS_OK;
}
/*
More information about the samba-technical
mailing list