um: Remove strlcpy declaration
PATCH 1/1 um: Remove strlcpy declaration
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
--- arch/um/include/shared/user.h | 1 - arch/um/os-Linux/umid.c | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-)
arch/um/include/shared/user.h +0 -1
@@ -50,7 +50,6 @@ static inline int printk(const char *fmt, ...)#endif extern int in_aton (char *str); -extern size_t strlcpy (char *,const char *,size_t );extern size_t strlcat (char *,const char *,size_t );extern size_t strscpy (char *,const char *,size_t );
arch/um/os-Linux/umid.c +3 -3
@@ -40,7 +40,7 @@ static int __init make_uml_dir(void) __func__); goto err; } -strlcpy (dir, home,sizeof (dir)); +strscpy (dir, home,sizeof (dir)); uml_dir++; }strlcat (dir, uml_dir,sizeof (dir));
@@ -243,7 +243,7 @@ int __init set_umid(char *name)if (strlen (name) >UMID_LEN -1 )return -E2BIG ; -strlcpy (umid, name,sizeof (umid)); +strscpy (umid, name,sizeof (umid));return 0 ; }
@@ -262,7 +262,7 @@ static int __init make_umid(void)make_uml_dir ();if (*umid =='\0' ) { -strlcpy (tmp, uml_dir,sizeof (tmp)); +strscpy (tmp, uml_dir,sizeof (tmp));strlcat (tmp,"XXXXXX" ,sizeof (tmp)); fd =mkstemp (tmp);if (fd <0 ) {
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
Quoted 8 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
No return values were used, so direct replacement is safe.
Quoted 4 lines
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89Signed-off-by Azeem Shaikh <[email protected]>
Signature · 1 line
Kees Cook
Kees Cook
AppliedQuoted 9 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
No return values were used, so direct replacement is safe.[...]
Applied, thanks!
[1/1] um: Remove strlcpy declaration
https://git.kernel.org/kees/c/61ce78f29a69
Best regards,
Signature · 1 line
Kees Cook