blob: e7ff4a0615894dedcd8ae29ef2d1381e1f974d3b [file] [log] [blame]
Joel Peshkin369d87a2021-04-11 11:21:58 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Broadcom
4 */
5
Joel Peshkin369d87a2021-04-11 11:21:58 +02006#include <command.h>
7
8static int do_test_stackprot_fail(struct cmd_tbl *cmdtp, int flag, int argc,
9 char *const argv[])
10{
Tom Rinie89befe2021-05-24 14:19:05 -040011 /*
12 * In order to avoid having the compiler optimize away the stack smashing
13 * we need to do a little something here.
14 */
Joel Peshkin369d87a2021-04-11 11:21:58 +020015 char a[128];
16
17 memset(a, 0xa5, 512);
Tom Rinie89befe2021-05-24 14:19:05 -040018
Heinrich Schuchardteda84292022-02-04 10:50:04 +010019 printf("We have smashed our stack as this should not exceed 128: sizeof(a) = %zd\n",
20 strlen(a));
Tom Rinie89befe2021-05-24 14:19:05 -040021
Joel Peshkin369d87a2021-04-11 11:21:58 +020022 return 0;
23}
24
25U_BOOT_CMD(stackprot_test, 1, 1, do_test_stackprot_fail,
26 "test stack protector fail", "");