diff options
author | bcook <> | 2021-03-27 11:17:58 +0000 |
---|---|---|
committer | bcook <> | 2021-03-27 11:17:58 +0000 |
commit | 5d4b8b6f9a8de0dda3e5c12178bbb427e7f32037 (patch) | |
tree | 295db949e7f61f7205dafedf282828f9cca50960 /src | |
parent | c4237dcb1d0434d3e0a7eae44d91fe4001046f52 (diff) | |
download | openbsd-5d4b8b6f9a8de0dda3e5c12178bbb427e7f32037.tar.gz openbsd-5d4b8b6f9a8de0dda3e5c12178bbb427e7f32037.tar.bz2 openbsd-5d4b8b6f9a8de0dda3e5c12178bbb427e7f32037.zip |
Handle dynamic definition of SIGSTKSZ as of glibc 2.34 on Linux.
ok bluhm@, inoguchi@, tb@, deraadt@
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/explicit_bzero/explicit_bzero.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/regress/lib/libc/explicit_bzero/explicit_bzero.c b/src/regress/lib/libc/explicit_bzero/explicit_bzero.c index 34c60baa8a..9c0e917829 100644 --- a/src/regress/lib/libc/explicit_bzero/explicit_bzero.c +++ b/src/regress/lib/libc/explicit_bzero/explicit_bzero.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: explicit_bzero.c,v 1.6 2014/07/11 01:10:35 matthew Exp $ */ | 1 | /* $OpenBSD: explicit_bzero.c,v 1.7 2021/03/27 11:17:58 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Google Inc. | 3 | * Copyright (c) 2014 Google Inc. |
4 | * | 4 | * |
@@ -18,6 +18,7 @@ | |||
18 | #include <assert.h> | 18 | #include <assert.h> |
19 | #include <errno.h> | 19 | #include <errno.h> |
20 | #include <signal.h> | 20 | #include <signal.h> |
21 | #include <stdlib.h> | ||
21 | #include <string.h> | 22 | #include <string.h> |
22 | #include <unistd.h> | 23 | #include <unistd.h> |
23 | 24 | ||
@@ -36,20 +37,34 @@ enum { | |||
36 | SECRETBYTES = SECRETCOUNT * sizeof(secret) | 37 | SECRETBYTES = SECRETCOUNT * sizeof(secret) |
37 | }; | 38 | }; |
38 | 39 | ||
39 | static char altstack[SIGSTKSZ + SECRETBYTES]; | 40 | /* |
41 | * As of glibc 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer | ||
42 | * constant on Linux. SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ). | ||
43 | */ | ||
44 | static char *altstack; | ||
45 | #define ALTSTACK_SIZE (SIGSTKSZ + SECRETBYTES) | ||
40 | 46 | ||
41 | static void | 47 | static void |
42 | setup_stack(void) | 48 | setup_stack(void) |
43 | { | 49 | { |
50 | altstack = calloc(1, ALTSTACK_SIZE); | ||
51 | ASSERT_NE(NULL, altstack); | ||
52 | |||
44 | const stack_t sigstk = { | 53 | const stack_t sigstk = { |
45 | .ss_sp = altstack, | 54 | .ss_sp = altstack, |
46 | .ss_size = sizeof(altstack), | 55 | .ss_size = ALTSTACK_SIZE |
47 | }; | 56 | }; |
48 | 57 | ||
49 | ASSERT_EQ(0, sigaltstack(&sigstk, NULL)); | 58 | ASSERT_EQ(0, sigaltstack(&sigstk, NULL)); |
50 | } | 59 | } |
51 | 60 | ||
52 | static void | 61 | static void |
62 | cleanup_stack(void) | ||
63 | { | ||
64 | free(altstack); | ||
65 | } | ||
66 | |||
67 | static void | ||
53 | assert_on_stack(void) | 68 | assert_on_stack(void) |
54 | { | 69 | { |
55 | stack_t cursigstk; | 70 | stack_t cursigstk; |
@@ -129,7 +144,7 @@ test_without_bzero() | |||
129 | char buf[SECRETBYTES]; | 144 | char buf[SECRETBYTES]; |
130 | assert_on_stack(); | 145 | assert_on_stack(); |
131 | populate_secret(buf, sizeof(buf)); | 146 | populate_secret(buf, sizeof(buf)); |
132 | char *res = memmem(altstack, sizeof(altstack), buf, sizeof(buf)); | 147 | char *res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf)); |
133 | ASSERT_NE(NULL, res); | 148 | ASSERT_NE(NULL, res); |
134 | return (res); | 149 | return (res); |
135 | } | 150 | } |
@@ -140,7 +155,7 @@ test_with_bzero() | |||
140 | char buf[SECRETBYTES]; | 155 | char buf[SECRETBYTES]; |
141 | assert_on_stack(); | 156 | assert_on_stack(); |
142 | populate_secret(buf, sizeof(buf)); | 157 | populate_secret(buf, sizeof(buf)); |
143 | char *res = memmem(altstack, sizeof(altstack), buf, sizeof(buf)); | 158 | char *res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf)); |
144 | ASSERT_NE(NULL, res); | 159 | ASSERT_NE(NULL, res); |
145 | explicit_bzero(buf, sizeof(buf)); | 160 | explicit_bzero(buf, sizeof(buf)); |
146 | return (res); | 161 | return (res); |
@@ -183,15 +198,17 @@ main() | |||
183 | * on the stack. This sanity checks that call_on_stack() and | 198 | * on the stack. This sanity checks that call_on_stack() and |
184 | * populate_secret() work as intended. | 199 | * populate_secret() work as intended. |
185 | */ | 200 | */ |
186 | memset(altstack, 0, sizeof(altstack)); | 201 | memset(altstack, 0, ALTSTACK_SIZE); |
187 | call_on_stack(do_test_without_bzero); | 202 | call_on_stack(do_test_without_bzero); |
188 | 203 | ||
189 | /* | 204 | /* |
190 | * Now test with a call to explicit_bzero() and check that we | 205 | * Now test with a call to explicit_bzero() and check that we |
191 | * *don't* find any instances of the secret data. | 206 | * *don't* find any instances of the secret data. |
192 | */ | 207 | */ |
193 | memset(altstack, 0, sizeof(altstack)); | 208 | memset(altstack, 0, ALTSTACK_SIZE); |
194 | call_on_stack(do_test_with_bzero); | 209 | call_on_stack(do_test_with_bzero); |
195 | 210 | ||
211 | cleanup_stack(); | ||
212 | |||
196 | return (0); | 213 | return (0); |
197 | } | 214 | } |