All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: akpm@linux-foundation.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>, linux-mm@kvack.org
Subject: [PATCH 3/5] mm/thp: Fix strncpy warning
Date: Tue, 15 Jun 2021 21:02:40 +0100	[thread overview]
Message-ID: <20210615200242.1716568-4-willy@infradead.org> (raw)
In-Reply-To: <20210615200242.1716568-1-willy@infradead.org>

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.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 503c8e1aecc6..d513b0cd1161 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;
-- 
2.30.2



  parent reply	other threads:[~2021-06-15 20:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15 20:02 [PATCH 0/5] Remove warnings from today's mmotm Matthew Wilcox (Oracle)
2021-06-15 20:02 ` [PATCH 1/5] mm writeback,cgroup: Fix documentation Matthew Wilcox (Oracle)
2021-06-15 20:02 ` [PATCH 2/5] Fix hugetlb_basepage_index missing prototype warning Matthew Wilcox (Oracle)
2021-06-15 23:16   ` Hugh Dickins
2021-06-15 20:02 ` Matthew Wilcox (Oracle) [this message]
2021-06-15 20:02 ` [PATCH 4/5] mm/sparse-vmemmap: Fix documentation warning Matthew Wilcox (Oracle)
2021-06-15 20:02 ` [PATCH 5/5] mm: Fix alloc_vmemmap_page_list " Matthew Wilcox (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210615200242.1716568-4-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.