* [PATCH] mm/damon: fix stringop-overread warning in kunit test
@ 2021-09-20 10:01 Arnd Bergmann
2021-09-20 15:18 ` SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2021-09-20 10:01 UTC (permalink / raw)
To: SeongJae Park, Andrew Morton, Brendan Higgins
Cc: Arnd Bergmann, linux-mm, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
gcc-11 points out that strnlen() with a fixed length on a constant
input makes no sense:
In file included from mm/damon/dbgfs.c:623:
mm/damon/dbgfs-test.h: In function 'damon_dbgfs_test_str_to_target_ids':
mm/damon/dbgfs-test.h:23:47: error: 'strnlen' specified bound 128 exceeds source size 4 [-Werror=stringop-overread]
23 | answers = str_to_target_ids(question, strnlen(question, 128),
| ^~~~~~~~~~~~~~~~~~~~~~
mm/damon/dbgfs-test.h:30:47: error: 'strnlen' specified bound 128 exceeds source size 7 [-Werror=stringop-overread]
30 | answers = str_to_target_ids(question, strnlen(question, 128),
| ^~~~~~~~~~~~~~~~~~~~~~
mm/damon/dbgfs-test.h:37:47: error: 'strnlen' specified bound 128 exceeds source size 5 [-Werror=stringop-overread]
37 | answers = str_to_target_ids(question, strnlen(question, 128),
| ^~~~~~~~~~~~~~~~~~~~~~
Use a plain strlen() instead.
Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
mm/damon/dbgfs-test.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/mm/damon/dbgfs-test.h b/mm/damon/dbgfs-test.h
index 930e83bceef0..4eddcfa73996 100644
--- a/mm/damon/dbgfs-test.h
+++ b/mm/damon/dbgfs-test.h
@@ -20,27 +20,27 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test)
ssize_t nr_integers = 0, i;
question = "123";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers);
KUNIT_EXPECT_EQ(test, 123ul, answers[0]);
kfree(answers);
question = "123abc";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers);
KUNIT_EXPECT_EQ(test, 123ul, answers[0]);
kfree(answers);
question = "a123";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers);
kfree(answers);
question = "12 35";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers);
for (i = 0; i < nr_integers; i++)
@@ -48,7 +48,7 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test)
kfree(answers);
question = "12 35 46";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)3, nr_integers);
for (i = 0; i < nr_integers; i++)
@@ -56,7 +56,7 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test)
kfree(answers);
question = "12 35 abc 46";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers);
for (i = 0; i < 2; i++)
@@ -64,13 +64,13 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test)
kfree(answers);
question = "";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers);
kfree(answers);
question = "\n";
- answers = str_to_target_ids(question, strnlen(question, 128),
+ answers = str_to_target_ids(question, strlen(question),
&nr_integers);
KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers);
kfree(answers);
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/damon: fix stringop-overread warning in kunit test
2021-09-20 10:01 [PATCH] mm/damon: fix stringop-overread warning in kunit test Arnd Bergmann
@ 2021-09-20 15:18 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2021-09-20 15:18 UTC (permalink / raw)
To: Arnd Bergmann
Cc: SeongJae Park, Andrew Morton, Brendan Higgins, Arnd Bergmann,
linux-mm, linux-kernel
On Mon, 20 Sep 2021 12:01:23 +0200 Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> gcc-11 points out that strnlen() with a fixed length on a constant
> input makes no sense:
>
> In file included from mm/damon/dbgfs.c:623:
> mm/damon/dbgfs-test.h: In function 'damon_dbgfs_test_str_to_target_ids':
> mm/damon/dbgfs-test.h:23:47: error: 'strnlen' specified bound 128 exceeds source size 4 [-Werror=stringop-overread]
> 23 | answers = str_to_target_ids(question, strnlen(question, 128),
> | ^~~~~~~~~~~~~~~~~~~~~~
> mm/damon/dbgfs-test.h:30:47: error: 'strnlen' specified bound 128 exceeds source size 7 [-Werror=stringop-overread]
> 30 | answers = str_to_target_ids(question, strnlen(question, 128),
> | ^~~~~~~~~~~~~~~~~~~~~~
> mm/damon/dbgfs-test.h:37:47: error: 'strnlen' specified bound 128 exceeds source size 5 [-Werror=stringop-overread]
> 37 | answers = str_to_target_ids(question, strnlen(question, 128),
> | ^~~~~~~~~~~~~~~~~~~~~~
>
> Use a plain strlen() instead.
>
> Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Thank you for the patch! However, a same change has already merged[1] in -mm.
Sorry for that.
[1] https://lore.kernel.org/mm-commits/20210915033531.IdrhacHQk%25akpm@linux-foundation.org/
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-20 15:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 10:01 [PATCH] mm/damon: fix stringop-overread warning in kunit test Arnd Bergmann
2021-09-20 15:18 ` SeongJae Park
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.