s3: smbd: Ensure dirpath is set to ".", not "\0" so it is always a valid path.
authorJeremy Allison <jra@samba.org>
Wed, 22 Aug 2018 20:37:04 +0000 (13:37 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 11 Sep 2018 20:45:10 +0000 (22:45 +0200)
Cleanup of the internals of unix_convert().

Ensure check_parent_exists() returns this in the non-optimization
case. Ensure unix_convert() initializes dirpath to ".".

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/smbd/filename.c

index 479d532327a039981dc3740abc6a1936ff9b372b..16d0f340102672766807d071f04c9d44029a6987 100644 (file)
@@ -236,6 +236,24 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
 
   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;
 }
 
@@ -601,7 +619,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                                        goto err;
                                }
                                /* dirpath must exist. */
-                               dirpath = talloc_strdup(ctx,"");
+                               dirpath = talloc_strdup(ctx,".");
                                if (dirpath == NULL) {
                                        status = NT_STATUS_NO_MEMORY;
                                        goto err;
@@ -638,7 +656,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
         * building the directories with talloc_asprintf and free it.
         */
 
-       if ((dirpath == NULL) && (!(dirpath = talloc_strdup(ctx,"")))) {
+       if ((dirpath == NULL) && (!(dirpath = talloc_strdup(ctx,".")))) {
                DEBUG(0, ("talloc_strdup failed\n"));
                status = NT_STATUS_NO_MEMORY;
                goto err;
@@ -1038,7 +1056,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                                        size_t start_ofs =
                                            start - smb_fname->base_name;
 
-                                       if (*dirpath != '\0') {
+                                       if (!ISDOT(dirpath)) {
                                                tmp = talloc_asprintf(
                                                        smb_fname, "%s/%s",
                                                        dirpath, unmangled);
@@ -1073,7 +1091,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                                size_t start_ofs =
                                    start - smb_fname->base_name;
 
-                               if (*dirpath != '\0') {
+                               if (!ISDOT(dirpath)) {
                                        tmp = talloc_asprintf(smb_fname,
                                                "%s/%s/%s", dirpath,
                                                found_name, end+1);
@@ -1098,7 +1116,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                                size_t start_ofs =
                                    start - smb_fname->base_name;
 
-                               if (*dirpath != '\0') {
+                               if (!ISDOT(dirpath)) {
                                        tmp = talloc_asprintf(smb_fname,
                                                "%s/%s", dirpath,
                                                found_name);
@@ -1139,7 +1157,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                 * Add to the dirpath that we have resolved so far.
                 */
 
-               if (*dirpath != '\0') {
+               if (!ISDOT(dirpath)) {
                        char *tmp = talloc_asprintf(ctx,
                                        "%s/%s", dirpath, start);
                        if (!tmp) {
@@ -1209,7 +1227,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
        return NT_STATUS_OK;
  fail:
        DEBUG(10, ("dirpath = [%s] start = [%s]\n", dirpath, start));
-       if (dirpath && *dirpath != '\0') {
+       if (dirpath && !ISDOT(dirpath)) {
                smb_fname->base_name = talloc_asprintf(smb_fname, "%s/%s",
                                                       dirpath, start);
        } else {