Commit 8297ca5e authored by Ole Wiedemann's avatar Ole Wiedemann Committed by Greg Kroah-Hartman

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: default avatarOle Wiedemann <ole.wiedemann@fau.de>
Co-developed-by: default avatarSebastian Scherbel <sebastian.scherbel@fau.de>
Signed-off-by: default avatarSebastian Scherbel <sebastian.scherbel@fau.de>
Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
Acked-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
Acked-by: default avatarTodd Kjos <tkjos@google.com>
Link: https://lore.kernel.org/r/20191213131032.22579-1-ole.wiedemann@fau.deSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cdb9c044
...@@ -537,14 +537,14 @@ static int set_name(struct ashmem_area *asma, void __user *name) ...@@ -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); len = strncpy_from_user(local_name, name, ASHMEM_NAME_LEN);
if (len < 0) if (len < 0)
return len; return len;
if (len == ASHMEM_NAME_LEN)
local_name[ASHMEM_NAME_LEN - 1] = '\0';
mutex_lock(&ashmem_mutex); mutex_lock(&ashmem_mutex);
/* cannot change an existing mapping's name */ /* cannot change an existing mapping's name */
if (asma->file) if (asma->file)
ret = -EINVAL; ret = -EINVAL;
else 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); mutex_unlock(&ashmem_mutex);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment