diff options
| author | Thorsten Blum <thorsten.blum@linux.dev> | 2026-01-11 16:12:58 +0300 |
|---|---|---|
| committer | Tyler Hicks <code@tyhicks.com> | 2026-01-13 05:21:27 +0300 |
| commit | 99853d9daef240a45e161d0e33487cda4810b999 (patch) | |
| tree | 381960a1a0c054316048b6c020d574d3477943a1 | |
| parent | 6ba673331340dabcff4a3ca91cc67761ba74c518 (diff) | |
| download | linux-99853d9daef240a45e161d0e33487cda4810b999.tar.xz | |
ecryptfs: Replace memcpy + NUL termination in ecryptfs_copy_filename
Use kmemdup_nul() to copy 'name' instead of using memcpy() followed by a
manual NUL termination. Remove the local return variable and the goto
label to simplify the code. No functional changes.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Acked-by: Tyler Hicks <code@tyhicks.com>
Signed-off-by: Tyler Hicks <code@tyhicks.com>
| -rw-r--r-- | fs/ecryptfs/crypto.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index c2ec043857f2..978d151e892f 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -1418,21 +1418,11 @@ out: static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_size, const char *name, size_t name_size) { - int rc = 0; - - (*copied_name) = kmalloc((name_size + 1), GFP_KERNEL); - if (!(*copied_name)) { - rc = -ENOMEM; - goto out; - } - memcpy((void *)(*copied_name), (void *)name, name_size); - (*copied_name)[(name_size)] = '\0'; /* Only for convenience - * in printing out the - * string in debug - * messages */ + (*copied_name) = kmemdup_nul(name, name_size, GFP_KERNEL); + if (!(*copied_name)) + return -ENOMEM; (*copied_name_size) = name_size; -out: - return rc; + return 0; } /** |
