]>
Commit | Line | Data |
---|---|---|
2b778ceb | 1 | /* Copyright (C) 2003-2021 Free Software Foundation, Inc. |
a15698cb | 2 | This file is part of the GNU C Library. |
a15698cb UD |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
a15698cb UD |
17 | |
18 | #include <setjmp.h> | |
19 | #include <signal.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <sys/types.h> | |
23 | ||
24 | static sigjmp_buf jmpbuf; | |
25 | ||
26 | static void | |
27 | sig_handler (int signo) | |
28 | { | |
29 | siglongjmp (jmpbuf, 1); | |
30 | } | |
31 | ||
32 | static int | |
33 | do_test (void) | |
34 | { | |
35 | char *p = NULL; | |
6c8bbad9 SP |
36 | /* gcc can overwrite the success written value by scheduling instructions |
37 | around sprintf. It is allowed to do this since according to C99 the first | |
38 | argument of sprintf is a character array and NULL is not a valid character | |
39 | array. Mark the return value as volatile so that it gets reloaded on | |
40 | return. */ | |
41 | volatile int ret = 0; | |
a15698cb | 42 | |
62ad2abc | 43 | if (signal (SIGSEGV, &sig_handler) == SIG_ERR) |
a15698cb | 44 | { |
62ad2abc RM |
45 | perror ("installing SIGSEGV handler"); |
46 | return 1; | |
a15698cb UD |
47 | } |
48 | ||
49 | puts ("Attempting to sprintf to null ptr"); | |
50 | if (setjmp (jmpbuf)) | |
51 | { | |
52 | puts ("Exiting main..."); | |
6c8bbad9 | 53 | return ret; |
a15698cb UD |
54 | } |
55 | ||
56 | sprintf (p, "This should segv\n"); | |
57 | ||
58 | return 1; | |
59 | } | |
60 | ||
61 | #define TEST_FUNCTION do_test () | |
62 | #include "../test-skeleton.c" |