From: Matthew Wilcox (Oracle) Date: Thu, 1 Jul 2021 01:52:11 +0000 (-0700) Subject: mm/thp: fix strncpy warning X-Git-Tag: irq-urgent-2021-07-11~67^2~96 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1212e00c93a8016dfd70d209f428f8e0edd5856f;p=users%2Fdwmw2%2Flinux.git mm/thp: fix strncpy warning Using MAX_INPUT_BUF_SZ as the maximum length of the string makes fortify complain as it thinks the string might be longer than the buffer, and if it is, we will end up with a "string" that is missing a NUL terminator. It's trivial to show that 'tok' points to a NUL-terminated string which is less than MAX_INPUT_BUF_SZ in length, so we may as well just use strcpy() and avoid the warning. Link: https://lkml.kernel.org/r/20210615200242.1716568-4-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Cc: Mike Kravetz Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 503c8e1aecc6b..d513b0cd1161d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3101,7 +3101,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, tok = strsep(&buf, ","); if (tok) { - strncpy(file_path, tok, MAX_INPUT_BUF_SZ); + strcpy(file_path, tok); } else { ret = -EINVAL; goto out;