block: Replace deprecated strcpy in devt_from_devname
PATCH RESEND 1/1 block: Replace deprecated strcpy in devt_from_devname
Use strnlen() and sizeof(s) instead of hard-coding 31 bytes.
strcpy() is deprecated [1] and uses an additional strlen() internally; use memcpy() directly since we already know the length of 'name' and that it is guaranteed to be NUL-terminated.
Signed-off-by Thorsten Blum <[email protected]>
--- block/early-lookup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
block/early-lookup.c +3 -2
@@ -155,10 +155,11 @@ static int __init devt_from_devname(const char *name, dev_t *devt)int part;char s[32 ];char *p; +size_t name_len =strnlen (name,sizeof (s)); -if (strlen (name) >31 ) +if (name_len ==sizeof (s))return -EINVAL ; -strcpy (s, name); +memcpy (s, name, name_len +1 );for (p = s; *p; p++) {if (*p =='/' ) *p ='!' ;
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4