aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOle Wiedemann <[email protected]>2019-12-13 14:10:32 +0100
committerGreg Kroah-Hartman <[email protected]>2020-01-14 16:17:11 +0100
commit8297ca5e8c70ddb58cf03cd0411929ab87a44860 (patch)
tree5d82c354dc71d56e9e50f40cff4f6865dca5054d
parentcdb9c044f92b78557e5e535819a932caeff81668 (diff)
staging: android: ashmem: Replace strcpy with strscpy
Replaced strcpy call with safer strscpy call with given length. This elimates the need to manually null-terminate the given string, since strscpy will null terminate the destination anyway.: Signed-off-by: Ole Wiedemann <[email protected]> Co-developed-by: Sebastian Scherbel <[email protected]> Signed-off-by: Sebastian Scherbel <[email protected]> Acked-by: Christian Brauner <[email protected]> Acked-by: Joel Fernandes (Google) <[email protected]> Acked-by: Todd Kjos <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
-rw-r--r--drivers/staging/android/ashmem.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 74d497d39c5a..5891d0744a76 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -537,14 +537,14 @@ static int set_name(struct ashmem_area *asma, void __user *name)
len = strncpy_from_user(local_name, name, ASHMEM_NAME_LEN);
if (len < 0)
return len;
- if (len == ASHMEM_NAME_LEN)
- local_name[ASHMEM_NAME_LEN - 1] = '\0';
+
mutex_lock(&ashmem_mutex);
/* cannot change an existing mapping's name */
if (asma->file)
ret = -EINVAL;
else
- strcpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name);
+ strscpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name,
+ ASHMEM_NAME_LEN);
mutex_unlock(&ashmem_mutex);
return ret;