summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/malloc-wrapper.c
diff options
context:
space:
mode:
authorbeck <>2014-04-16 03:24:53 +0000
committerbeck <>2014-04-16 03:24:53 +0000
commit5ebad8aceae77c6da6a1e47c3f7e70e8ffae3dae (patch)
treee60f8186026303c75b1e90f9e9bd192dc1b02171 /src/lib/libcrypto/malloc-wrapper.c
parent3c1ef33c56df584ddf4397f1cf1c34bf828b86da (diff)
downloadopenbsd-5ebad8aceae77c6da6a1e47c3f7e70e8ffae3dae.tar.gz
openbsd-5ebad8aceae77c6da6a1e47c3f7e70e8ffae3dae.tar.bz2
openbsd-5ebad8aceae77c6da6a1e47c3f7e70e8ffae3dae.zip
Your operating system memory allocation functions are your friend. If they
are not please fix your operating system. Replace mem.c with an API-compatible wrapper that just calls the system functions and does not allow a one word modification of a variable in a running shared library to turn on memory debug functions that expose things that should not be seen. ok tedu@
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/malloc-wrapper.c199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/lib/libcrypto/malloc-wrapper.c b/src/lib/libcrypto/malloc-wrapper.c
new file mode 100644
index 0000000000..49d7c572c8
--- /dev/null
+++ b/src/lib/libcrypto/malloc-wrapper.c
@@ -0,0 +1,199 @@
1/* $OpenBSD: malloc-wrapper.c,v 1.1 2014/04/16 03:24:53 beck Exp $ */
2/*
3 * Copyright (c) 2014 Bob Beck
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21int
22CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t),
23 void (*f)(void *))
24{
25 return 0;
26}
27
28int
29CRYPTO_set_mem_ex_functions(void *(*m)(size_t, const char *, int),
30 void *(*r)(void *, size_t, const char *, int), void (*f)(void *))
31{
32 return 0;
33}
34
35int
36CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
37{
38 return 0;
39}
40
41int
42CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t, const char *, int),
43 void (*f)(void *))
44{
45 return 0;
46}
47
48int
49CRYPTO_set_mem_debug_functions(void (*m)(void *, int, const char *, int, int),
50 void (*r)(void *, void *, int, const char *, int, int),
51 void (*f)(void *, int), void (*so)(long), long (*go)(void))
52{
53 return 0;
54}
55
56
57void
58CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
59 void (**f)(void *))
60{
61 if (m != NULL)
62 *m = malloc;
63 if (r != NULL)
64 *r = realloc;
65 if (f != NULL)
66 *f = free;
67}
68
69void
70CRYPTO_get_mem_ex_functions(void *(**m)(size_t, const char *, int),
71 void *(**r)(void *, size_t, const char *, int), void (**f)(void *))
72{
73 if (m != NULL)
74 *m = NULL;
75 if (r != NULL)
76 *r = NULL;
77 if (f != NULL)
78 *f = free;
79}
80
81void
82CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
83{
84 if (m != NULL)
85 *m = malloc;
86 if (f != NULL)
87 *f = free;
88}
89
90void
91CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t, const char *, int),
92 void (**f)(void *))
93{
94 if (m != NULL)
95 *m = NULL;
96 if (f != NULL)
97 *f = free;
98}
99
100void
101CRYPTO_get_mem_debug_functions(void (**m)(void *, int, const char *, int, int),
102 void (**r)(void *, void *, int, const char *, int, int),
103 void (**f)(void *, int), void (**so)(long), long (**go)(void))
104{
105 if (m != NULL)
106 *m = NULL;
107 if (r != NULL)
108 *r = NULL;
109 if (f != NULL)
110 *f = NULL;
111 if (so != NULL)
112 *so = NULL;
113 if (go != NULL)
114 *go = NULL;
115}
116
117
118void *
119CRYPTO_malloc_locked(int num, const char *file, int line)
120{
121 void *ret = NULL;
122
123 if (num <= 0)
124 return NULL;
125 return malloc(num);
126}
127
128void
129CRYPTO_free_locked(void *ptr)
130{
131 free(ptr);
132}
133
134void *
135CRYPTO_malloc(int num, const char *file, int line)
136{
137 if (num <= 0)
138 return NULL;
139 return malloc(num);
140}
141
142char *
143CRYPTO_strdup(const char *str, const char *file, int line)
144{
145 return strdup(str);
146}
147
148void *
149CRYPTO_realloc(void *ptr, int num, const char *file, int line)
150{
151 if (num <= 0)
152 return NULL;
153
154 return realloc(ptr, num);
155}
156
157void *
158CRYPTO_realloc_clean(void *ptr, int old_len, int num, const char *file,
159int line)
160{
161 void *ret = NULL;
162
163 if (num <= 0)
164 return NULL;
165 if (num < old_len)
166 return NULL; /* original does not support shrinking */
167 ret = malloc(num);
168 if (ret && ptr && old_len > 0) {
169 memcpy(ret, ptr, old_len);
170 explicit_bzero(ptr, old_len);
171 free(ptr);
172 }
173 return ret;
174}
175
176void
177CRYPTO_free(void *ptr)
178{
179 free(ptr);
180}
181
182void *
183CRYPTO_remalloc(void *a, int num, const char *file, int line)
184{
185 free(a);
186 return malloc(num);
187}
188
189void
190CRYPTO_set_mem_debug_options(long bits)
191{
192 return;
193}
194
195long
196CRYPTO_get_mem_debug_options(void)
197{
198 return 0;
199}