Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / libraries / libressl / fix-build-with-glibc.patch
blobdb482bcb35da38cc74edb2673a16075f770ea913
1 diff --git a/tests/explicit_bzero.c b/tests/explicit_bzero.c
2 index 34c60baa8a..9c0e917829 100644
3 --- a/tests/explicit_bzero.c
4 +++ b/tests/explicit_bzero.c
5 @@ -1,4 +1,4 @@
6 -/* $OpenBSD: explicit_bzero.c,v 1.6 2014/07/11 01:10:35 matthew Exp $ */
7 +/* $OpenBSD: explicit_bzero.c,v 1.7 2021/03/27 11:17:58 bcook Exp $ */
8 /*
9 * Copyright (c) 2014 Google Inc.
11 @@ -18,6 +18,7 @@
12 #include <assert.h>
13 #include <errno.h>
14 #include <signal.h>
15 +#include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
19 @@ -36,19 +37,33 @@ enum {
20 SECRETBYTES = SECRETCOUNT * sizeof(secret)
23 -static char altstack[SIGSTKSZ + SECRETBYTES];
24 +/*
25 + * As of glibc 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer
26 + * constant on Linux. SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ).
27 + */
28 +static char *altstack;
29 +#define ALTSTACK_SIZE (SIGSTKSZ + SECRETBYTES)
31 static void
32 setup_stack(void)
34 + altstack = calloc(1, ALTSTACK_SIZE);
35 + ASSERT_NE(NULL, altstack);
37 const stack_t sigstk = {
38 .ss_sp = altstack,
39 - .ss_size = sizeof(altstack),
40 + .ss_size = ALTSTACK_SIZE
43 ASSERT_EQ(0, sigaltstack(&sigstk, NULL));
46 +static void
47 +cleanup_stack(void)
49 + free(altstack);
52 static void
53 assert_on_stack(void)
55 @@ -129,7 +144,7 @@ test_without_bzero()
56 char buf[SECRETBYTES];
57 assert_on_stack();
58 populate_secret(buf, sizeof(buf));
59 - char *res = memmem(altstack, sizeof(altstack), buf, sizeof(buf));
60 + char *res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf));
61 ASSERT_NE(NULL, res);
62 return (res);
64 @@ -140,7 +155,7 @@ test_with_bzero()
65 char buf[SECRETBYTES];
66 assert_on_stack();
67 populate_secret(buf, sizeof(buf));
68 - char *res = memmem(altstack, sizeof(altstack), buf, sizeof(buf));
69 + char *res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf));
70 ASSERT_NE(NULL, res);
71 explicit_bzero(buf, sizeof(buf));
72 return (res);
73 @@ -183,15 +198,17 @@ main()
74 * on the stack. This sanity checks that call_on_stack() and
75 * populate_secret() work as intended.
77 - memset(altstack, 0, sizeof(altstack));
78 + memset(altstack, 0, ALTSTACK_SIZE);
79 call_on_stack(do_test_without_bzero);
82 * Now test with a call to explicit_bzero() and check that we
83 * *don't* find any instances of the secret data.
85 - memset(altstack, 0, sizeof(altstack));
86 + memset(altstack, 0, ALTSTACK_SIZE);
87 call_on_stack(do_test_with_bzero);
89 + cleanup_stack();
91 return (0);