Skip to content

Commit 99853d9

Browse files
tobluxtyhicks
authored andcommitted
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>
1 parent 6ba6733 commit 99853d9

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

fs/ecryptfs/crypto.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,21 +1418,11 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename,
14181418
static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_size,
14191419
const char *name, size_t name_size)
14201420
{
1421-
int rc = 0;
1422-
1423-
(*copied_name) = kmalloc((name_size + 1), GFP_KERNEL);
1424-
if (!(*copied_name)) {
1425-
rc = -ENOMEM;
1426-
goto out;
1427-
}
1428-
memcpy((void *)(*copied_name), (void *)name, name_size);
1429-
(*copied_name)[(name_size)] = '\0'; /* Only for convenience
1430-
* in printing out the
1431-
* string in debug
1432-
* messages */
1421+
(*copied_name) = kmemdup_nul(name, name_size, GFP_KERNEL);
1422+
if (!(*copied_name))
1423+
return -ENOMEM;
14331424
(*copied_name_size) = name_size;
1434-
out:
1435-
return rc;
1425+
return 0;
14361426
}
14371427

14381428
/**

0 commit comments

Comments
 (0)