Skip to content

Commit f5ff432

Browse files
azeemshaikh38richardweinberger
authored andcommitted
um: Remove strlcpy usage
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] KSPP#89 Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com> [rw: Massaged subject] Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 2ccdd1b commit f5ff432

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

arch/um/include/shared/user.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ static inline int printk(const char *fmt, ...)
5050
#endif
5151

5252
extern int in_aton(char *str);
53-
extern size_t strlcpy(char *, const char *, size_t);
5453
extern size_t strlcat(char *, const char *, size_t);
5554
extern size_t strscpy(char *, const char *, size_t);
5655

arch/um/os-Linux/umid.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int __init make_uml_dir(void)
4040
__func__);
4141
goto err;
4242
}
43-
strlcpy(dir, home, sizeof(dir));
43+
strscpy(dir, home, sizeof(dir));
4444
uml_dir++;
4545
}
4646
strlcat(dir, uml_dir, sizeof(dir));
@@ -243,7 +243,7 @@ int __init set_umid(char *name)
243243
if (strlen(name) > UMID_LEN - 1)
244244
return -E2BIG;
245245

246-
strlcpy(umid, name, sizeof(umid));
246+
strscpy(umid, name, sizeof(umid));
247247

248248
return 0;
249249
}
@@ -262,7 +262,7 @@ static int __init make_umid(void)
262262
make_uml_dir();
263263

264264
if (*umid == '\0') {
265-
strlcpy(tmp, uml_dir, sizeof(tmp));
265+
strscpy(tmp, uml_dir, sizeof(tmp));
266266
strlcat(tmp, "XXXXXX", sizeof(tmp));
267267
fd = mkstemp(tmp);
268268
if (fd < 0) {

0 commit comments

Comments
 (0)