xref: /netbsd-src/tests/usr.bin/c++/t_asan_heap_overflow.sh (revision ff295ecc8d2fa6aceb053ae84d728a60ab0be055)
1*ff295eccSmgorny#	$NetBSD: t_asan_heap_overflow.sh,v 1.3 2019/01/29 20:02:34 mgorny Exp $
28e4f836cSkamil#
3*ff295eccSmgorny# Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
48e4f836cSkamil# All rights reserved.
58e4f836cSkamil#
68e4f836cSkamil# This code is derived from software contributed to The NetBSD Foundation
78e4f836cSkamil# by Siddharth Muralee.
88e4f836cSkamil#
98e4f836cSkamil# Redistribution and use in source and binary forms, with or without
108e4f836cSkamil# modification, are permitted provided that the following conditions
118e4f836cSkamil# are met:
128e4f836cSkamil# 1. Redistributions of source code must retain the above copyright
138e4f836cSkamil#    notice, this list of conditions and the following disclaimer.
148e4f836cSkamil# 2. Redistributions in binary form must reproduce the above copyright
158e4f836cSkamil#    notice, this list of conditions and the following disclaimer in the
168e4f836cSkamil#    documentation and/or other materials provided with the distribution.
178e4f836cSkamil#
188e4f836cSkamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
198e4f836cSkamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
208e4f836cSkamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
218e4f836cSkamil# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
228e4f836cSkamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
238e4f836cSkamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
248e4f836cSkamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
258e4f836cSkamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
268e4f836cSkamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
278e4f836cSkamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
288e4f836cSkamil# POSSIBILITY OF SUCH DAMAGE.
298e4f836cSkamil#
308e4f836cSkamil
31*ff295eccSmgornyASAN_CODE='
328e4f836cSkamil#include <stdio.h>
338e4f836cSkamil#include <stdlib.h>
348e4f836cSkamil#include <string.h>
358e4f836cSkamilint foo(int);
36*ff295eccSmgorny#ifndef PIC_MAIN
378e4f836cSkamilint foo(int index) { int *x = (int *)malloc(20); int res = x[index * 4]; free(x); return res;}
38*ff295eccSmgorny#endif
39*ff295eccSmgorny#ifndef PIC_FOO
408e4f836cSkamilint main(int argc, char **argv) {foo(argc + 19); printf("CHECK\n"); exit(0);}
41*ff295eccSmgorny#endif
42*ff295eccSmgorny'
438e4f836cSkamil
44*ff295eccSmgornyasan_test_case heap_overflow "Heap Overflow example" heap-buffer-overflow
458e4f836cSkamil
468e4f836cSkamilatf_init_test_cases()
478e4f836cSkamil{
48*ff295eccSmgorny	asan_add_test_cases heap_overflow
498e4f836cSkamil}
50