From: Kevin Brodsky <[email protected]>

[ Upstream commit 5b6b2799f617b3259d551980fa94f290d96bc593 ]

GCC complains (with -O2) that the length is equal to the destination size,
which is indeed invalid.  Subtract 1 from the size of the array to leave
room for '\0'.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Kevin Brodsky <[email protected]>
Cc: Aruna Ramakrishna <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Keith Lucas <[email protected]>
Cc: Ryan Roberts <[email protected]>
Cc: Shuah Khan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
(cherry picked from commit 5b6b2799f617b3259d551980fa94f290d96bc593)
[Harshit: Backport to 6.12.y, fixes build time warning: warning:
‘strncpy’ specified bound 256 equals destination size in 6.12.y, this is
a clean cherry-pick]
Signed-off-by: Harshit Mogalapalli <[email protected]>
---
 tools/testing/selftests/mm/write_to_hugetlbfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/write_to_hugetlbfs.c 
b/tools/testing/selftests/mm/write_to_hugetlbfs.c
index 1289d311efd7..34c91f7e6128 100644
--- a/tools/testing/selftests/mm/write_to_hugetlbfs.c
+++ b/tools/testing/selftests/mm/write_to_hugetlbfs.c
@@ -89,7 +89,7 @@ int main(int argc, char **argv)
                        size = atoi(optarg);
                        break;
                case 'p':
-                       strncpy(path, optarg, sizeof(path));
+                       strncpy(path, optarg, sizeof(path) - 1);
                        break;
                case 'm':
                        if (atoi(optarg) >= MAX_METHOD) {
-- 
2.47.3


Reply via email to