From: Ralph Boehme Date: Tue, 5 May 2020 11:03:29 +0000 (+0200) Subject: smbd: pass translated_path as const to stat_cache_add() X-Git-Tag: ldb-2.2.0~660 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=28763125cff32d826929f7a261d2e5e1f5cd1ba7;p=thirdparty%2Fsamba.git smbd: pass translated_path as const to stat_cache_add() Prepares for doing more stuff with the translated_path in a subsequent commit. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 3a3e7774f05..b0b6e2981c3 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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, diff --git a/source3/smbd/statcache.c b/source3/smbd/statcache.c index 5162ec06ea9..3176ca06a71 100644 --- a/source3/smbd/statcache.c +++ b/source3/smbd/statcache.c @@ -45,13 +45,13 @@ */ 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); } /**