]> git.proxmox.com Git - mirror_frr.git/blame - tests/lib/test_segv.c
Merge pull request #10447 from ton31337/fix/json_with_whitespaces
[mirror_frr.git] / tests / lib / test_segv.c
CommitLineData
4d474fa3
DL
1/*
2 * SEGV / backtrace handling test.
3 *
4 * copied from test-sig.c
5 *
6 * Copyright (C) 2013 by David Lamparter, Open Source Routing.
7 * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
8 *
9 * This file is part of Quagga
10 *
11 * Quagga is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2, or (at your option) any
14 * later version.
15 *
16 * Quagga is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
896014f4
DL
21 * You should have received a copy of the GNU General Public License along
22 * with this program; see the file COPYING; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4d474fa3
DL
24 */
25
26#include <zebra.h>
27#include <sigevent.h>
28#include "lib/log.h"
29#include "lib/memory.h"
30
7cc91e67 31struct frr_signal_t sigs[] = {};
4d474fa3
DL
32
33struct thread_master *master;
34
68b8a15f
DL
35void func1(int *arg);
36void func3(void);
37
38void func1(int *arg)
4d474fa3 39{
d62a17ae 40 int *null = NULL;
41 *null += 1;
68b8a15f
DL
42 *arg = 1;
43}
44
45static void func2(size_t depth, int *arg)
46{
47 /* variable stack frame size */
48 int buf[depth];
49 for (size_t i = 0; i < depth; i++)
50 buf[i] = arg[i] + 1;
51 if (depth > 0)
52 func2(depth - 1, buf);
53 else
54 func1(&buf[0]);
55 for (size_t i = 0; i < depth; i++)
56 buf[i] = arg[i] + 2;
57}
58
59void func3(void)
60{
61 int buf[6];
62 func2(6, buf);
63}
64
cc9f21da 65static void threadfunc(struct thread *thread)
68b8a15f
DL
66{
67 func3();
4d474fa3
DL
68}
69
d62a17ae 70int main(void)
4d474fa3 71{
d62a17ae 72 master = thread_master_create(NULL);
73 signal_init(master, array_size(sigs), sigs);
4d474fa3 74
0bdeb5e5 75 zlog_aux_init("NONE: ", LOG_DEBUG);
4d474fa3 76
d62a17ae 77 thread_execute(master, threadfunc, 0, 0);
4d474fa3 78
d62a17ae 79 exit(0);
4d474fa3 80}