Skip to content

Commit 4f88590

Browse files
tobluxkawasaki
authored andcommitted
block: Replace deprecated strcpy in devt_from_devname
Use strnlen() and sizeof(s) instead of hard-coding 31 bytes. strcpy() is deprecated 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. Link: KSPP/linux#88 Signed-off-by: Thorsten Blum <[email protected]>
1 parent 00d5e5c commit 4f88590

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

block/early-lookup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ static int __init devt_from_devname(const char *name, dev_t *devt)
155155
int part;
156156
char s[32];
157157
char *p;
158+
size_t name_len = strnlen(name, sizeof(s));
158159

159-
if (strlen(name) > 31)
160+
if (name_len == sizeof(s))
160161
return -EINVAL;
161-
strcpy(s, name);
162+
memcpy(s, name, name_len + 1);
162163
for (p = s; *p; p++) {
163164
if (*p == '/')
164165
*p = '!';

0 commit comments

Comments
 (0)