Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/exec: check malloc() return in execveat concat()
@ 2026-11-13  7:23 zhangchujun
  2026-11-14  7:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: zhangchujun @ 2026-11-13  7:23 UTC (permalink / raw)
  To: kees, shuah
  Cc: akpm, richard.weiyang, linux-kselftest, linux-mm, linux-kernel,
	zhangchujun

concat() strcpy()s into the buffer returned by malloc() without
checking it for NULL.  If the allocation fails, the helper
dereferences NULL and crashes the test.

Check the allocation and exit with a failure message via
ksft_exit_fail_msg(), which is how the file already reports
unrecoverable errors.

Signed-off-by: zhangchujun <zhangchujun@cmss.chinamobile.com>

diff --git a/tools/testing/selftests/exec/execveat.c b/tools/testing/selftests/exec/execveat.c
index d37c068ed5fe..b70844a7a13c 100644
--- a/tools/testing/selftests/exec/execveat.c
+++ b/tools/testing/selftests/exec/execveat.c
@@ -138,6 +138,8 @@ static char *concat(const char *left, const char *right)
 {
 	char *result = malloc(strlen(left) + strlen(right) + 1);
 
+	if (!result)
+		ksft_exit_fail_msg("malloc failed\n");
 	strcpy(result, left);
 	strcat(result, right);
 	return result;
-- 
2.50.1.windows.1





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

end of thread, other threads:[~2026-11-14  7:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  7:23 [PATCH] selftests/exec: check malloc() return in execveat concat() zhangchujun
2026-11-14  7:23 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox