Skip to content

Commit 8016428

Browse files
KunWuChanwilldeacon
authored andcommitted
kselftest: arm64: Add a null pointer check
There is a 'malloc' call, which can be unsuccessful. This patch will add the malloc failure checking to avoid possible null dereference and give more information about test fail reasons. Signed-off-by: Kunwu Chan <chentao@kylinos.cn> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Link: https://lore.kernel.org/r/20240423082102.2018886-1-chentao@kylinos.cn Signed-off-by: Will Deacon <will@kernel.org>
1 parent b7fab1b commit 8016428

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/testing/selftests/arm64/tags/tags_test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdint.h>
77
#include <sys/prctl.h>
88
#include <sys/utsname.h>
9+
#include "../../kselftest.h"
910

1011
#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56)
1112
#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
@@ -21,6 +22,9 @@ int main(void)
2122
if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
2223
tbi_enabled = 1;
2324
ptr = (struct utsname *)malloc(sizeof(*ptr));
25+
if (!ptr)
26+
ksft_exit_fail_msg("Failed to allocate utsname buffer\n");
27+
2428
if (tbi_enabled)
2529
tag = 0x42;
2630
ptr = (struct utsname *)SET_TAG(ptr, tag);

0 commit comments

Comments
 (0)