Commit 99853d9d authored by Thorsten Blum's avatar Thorsten Blum Committed by Tyler Hicks
Browse files

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: default avatarThorsten Blum <thorsten.blum@linux.dev>
Acked-by: default avatarTyler Hicks <code@tyhicks.com>
Signed-off-by: default avatarTyler Hicks <code@tyhicks.com>
parent 6ba67333
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -1418,21 +1418,11 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename,
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;
}

/**