]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: pass translated_path as const to stat_cache_add()
authorRalph Boehme <slow@samba.org>
Tue, 5 May 2020 11:03:29 +0000 (13:03 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 5 May 2020 19:18:43 +0000 (19:18 +0000)
Prepares for doing more stuff with the translated_path in a subsequent commit.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/proto.h
source3/smbd/statcache.c

index 3a3e7774f05379342bd0d9eef036faf5d050e3ff..b0b6e2981c3757e0b2eaf6ba013f53223a23da9f 100644 (file)
@@ -1168,7 +1168,7 @@ ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
 /* The following definitions come from smbd/statcache.c  */
 
 void stat_cache_add( const char *full_orig_name,
-               char *translated_path,
+               const char *translated_path,
                bool case_sensitive);
 bool stat_cache_lookup(connection_struct *conn,
                        bool posix_paths,
index 5162ec06ea9c744cde5021d3fd91cad44cb928ca..3176ca06a71d92595b309e280a0c43a1f969fa1d 100644 (file)
  */
 
 void stat_cache_add( const char *full_orig_name,
-               char *translated_path,
+               const char *translated_path_in,
                bool case_sensitive)
 {
        size_t translated_path_length;
+       char *translated_path = NULL;
        char *original_path;
        size_t original_path_length;
-       char saved_char;
        TALLOC_CTX *ctx = talloc_tos();
 
        if (!lp_stat_cache()) {
@@ -67,6 +67,11 @@ void stat_cache_add( const char *full_orig_name,
                return;
        }
 
+       translated_path = talloc_strdup(ctx, translated_path_in);
+       if (translated_path == NULL) {
+               return;
+       }
+
        /*
         * If we are in case insentive mode, we don't need to
         * store names that need no translation - else, it
@@ -74,6 +79,7 @@ void stat_cache_add( const char *full_orig_name,
         */
 
        if (!case_sensitive && (strcmp(full_orig_name, translated_path) == 0)) {
+               TALLOC_FREE(translated_path);
                return;
        }
 
@@ -95,6 +101,7 @@ void stat_cache_add( const char *full_orig_name,
        }
 
        if (!original_path) {
+               TALLOC_FREE(translated_path);
                return;
        }
 
@@ -114,6 +121,7 @@ void stat_cache_add( const char *full_orig_name,
                                  translated_path,
                                  (unsigned long)translated_path_length));
                        TALLOC_FREE(original_path);
+                       TALLOC_FREE(translated_path);
                        return;
                }
 
@@ -125,7 +133,6 @@ void stat_cache_add( const char *full_orig_name,
        }
 
        /* Ensure we're null terminated. */
-       saved_char = translated_path[translated_path_length];
        translated_path[translated_path_length] = '\0';
 
        /*
@@ -143,8 +150,8 @@ void stat_cache_add( const char *full_orig_name,
                 original_path,
                 translated_path));
 
-       translated_path[translated_path_length] = saved_char;
        TALLOC_FREE(original_path);
+       TALLOC_FREE(translated_path);
 }
 
 /**