linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/powerpc: Fix strncpy usage
@ 2018-06-20 22:51 Breno Leitao
  2018-06-21 23:18 ` Segher Boessenkool
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Breno Leitao @ 2018-06-20 22:51 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Breno Leitao, Anshuman Khandual

There is a buffer overflow in dscr_inherit_test.c test. In main(), strncpy()'s
third argument is the lengh of the source, not the size of the destination
buffer, which makes strncpy() behaves like strcpy(), causing a buffer overflow
if argv[0] is bigger than LEN_MAX (100).

This patch simply limit the string copy to sizeof(prog) less 1 (space for \0).

CC: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 tools/testing/selftests/powerpc/dscr/dscr_inherit_exec_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/dscr/dscr_inherit_exec_test.c b/tools/testing/selftests/powerpc/dscr/dscr_inherit_exec_test.c
index 08a8b95e3bc1..638e0dc717d5 100644
--- a/tools/testing/selftests/powerpc/dscr/dscr_inherit_exec_test.c
+++ b/tools/testing/selftests/powerpc/dscr/dscr_inherit_exec_test.c
@@ -104,6 +104,6 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	strncpy(prog, argv[0], strlen(argv[0]));
+	strncpy(prog, argv[0], sizeof(prog) - 1);
 	return test_harness(dscr_inherit_exec, "dscr_inherit_exec_test");
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-07-11 13:24 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-20 22:51 [PATCH] selftests/powerpc: Fix strncpy usage Breno Leitao
2018-06-21 23:18 ` Segher Boessenkool
2018-06-22 14:43   ` Breno Leitao
2018-06-22 14:51     ` Christophe LEROY
2018-06-23  1:00       ` Segher Boessenkool
2018-06-22 15:15     ` Paul Clarke
2018-06-22 21:01       ` Al Dunsmuir
2018-06-23  1:10     ` Segher Boessenkool
2018-06-25 21:21       ` Breno Leitao
2018-06-25 21:30 ` [PATCH v2] " Breno Leitao
2018-06-26  5:24   ` Michael Ellerman
2018-06-26 13:13     ` Breno Leitao
2018-06-26 13:20 ` [PATCH v3 1/2] " Breno Leitao
2018-06-26 13:20   ` [PATCH v3 2/2] selftests/powerpc: Fix typos Breno Leitao
2018-07-11 13:24   ` [v3,1/2] selftests/powerpc: Fix strncpy usage Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).