summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbcook <>2015-09-12 15:25:33 +0000
committerbcook <>2015-09-12 15:25:33 +0000
commite0bdad806c920a73e1a6be88d274a87f6a59689d (patch)
tree466cfec9ce727265863909f693eddb156dbbd598
parent9cf967eb19ffcd73b7cde6533139e64730f8648c (diff)
downloadopenbsd-e0bdad806c920a73e1a6be88d274a87f6a59689d.tar.gz
openbsd-e0bdad806c920a73e1a6be88d274a87f6a59689d.tar.bz2
openbsd-e0bdad806c920a73e1a6be88d274a87f6a59689d.zip
Cleanup enginetest a bit.
It was the only thing preventing -Werror from building on some systems due to the unchecked asprintf's.
-rw-r--r--src/regress/lib/libcrypto/engine/enginetest.c188
1 files changed, 84 insertions, 104 deletions
diff --git a/src/regress/lib/libcrypto/engine/enginetest.c b/src/regress/lib/libcrypto/engine/enginetest.c
index 7a0b1a8751..0cb1d28d59 100644
--- a/src/regress/lib/libcrypto/engine/enginetest.c
+++ b/src/regress/lib/libcrypto/engine/enginetest.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -60,40 +60,35 @@
60#include <string.h> 60#include <string.h>
61#include <openssl/e_os2.h> 61#include <openssl/e_os2.h>
62 62
63#ifdef OPENSSL_NO_ENGINE
64int main(int argc, char *argv[])
65{
66 printf("No ENGINE support\n");
67 return(0);
68}
69#else
70#include <openssl/buffer.h> 63#include <openssl/buffer.h>
71#include <openssl/crypto.h> 64#include <openssl/crypto.h>
72#include <openssl/engine.h> 65#include <openssl/engine.h>
73#include <openssl/err.h> 66#include <openssl/err.h>
74 67
75static void display_engine_list(void) 68static void display_engine_list(void)
76 { 69{
77 ENGINE *h; 70 ENGINE *h;
78 int loop; 71 int loop;
79 72
80 h = ENGINE_get_first(); 73 h = ENGINE_get_first();
81 loop = 0; 74 loop = 0;
82 printf("listing available engine types\n"); 75 printf("listing available engine types\n");
83 while(h) 76 while (h) {
84 {
85 printf("engine %i, id = \"%s\", name = \"%s\"\n", 77 printf("engine %i, id = \"%s\", name = \"%s\"\n",
86 loop++, ENGINE_get_id(h), ENGINE_get_name(h)); 78 loop++, ENGINE_get_id(h), ENGINE_get_name(h));
87 h = ENGINE_get_next(h); 79 h = ENGINE_get_next(h);
88 } 80 }
81
89 printf("end of list\n"); 82 printf("end of list\n");
90 /* ENGINE_get_first() increases the struct_ref counter, so we 83 /*
91 must call ENGINE_free() to decrease it again */ 84 * ENGINE_get_first() increases the struct_ref counter, so we must call
85 * ENGINE_free() to decrease it again
86 */
92 ENGINE_free(h); 87 ENGINE_free(h);
93 } 88}
94 89
95int main(int argc, char *argv[]) 90int main(int argc, char *argv[])
96 { 91{
97 ENGINE *block[512]; 92 ENGINE *block[512];
98 char *id, *name; 93 char *id, *name;
99 ENGINE *ptr; 94 ENGINE *ptr;
@@ -107,156 +102,142 @@ int main(int argc, char *argv[])
107 ERR_load_crypto_strings(); 102 ERR_load_crypto_strings();
108 103
109 memset(block, 0, 512 * sizeof(ENGINE *)); 104 memset(block, 0, 512 * sizeof(ENGINE *));
110 if(((new_h1 = ENGINE_new()) == NULL) || 105 if (((new_h1 = ENGINE_new()) == NULL) ||
111 !ENGINE_set_id(new_h1, "test_id0") || 106 !ENGINE_set_id(new_h1, "test_id0") ||
112 !ENGINE_set_name(new_h1, "First test item") || 107 !ENGINE_set_name(new_h1, "First test item") ||
113 ((new_h2 = ENGINE_new()) == NULL) || 108 ((new_h2 = ENGINE_new()) == NULL) ||
114 !ENGINE_set_id(new_h2, "test_id1") || 109 !ENGINE_set_id(new_h2, "test_id1") ||
115 !ENGINE_set_name(new_h2, "Second test item") || 110 !ENGINE_set_name(new_h2, "Second test item") ||
116 ((new_h3 = ENGINE_new()) == NULL) || 111 ((new_h3 = ENGINE_new()) == NULL) ||
117 !ENGINE_set_id(new_h3, "test_id2") || 112 !ENGINE_set_id(new_h3, "test_id2") ||
118 !ENGINE_set_name(new_h3, "Third test item") || 113 !ENGINE_set_name(new_h3, "Third test item") ||
119 ((new_h4 = ENGINE_new()) == NULL) || 114 ((new_h4 = ENGINE_new()) == NULL) ||
120 !ENGINE_set_id(new_h4, "test_id3") || 115 !ENGINE_set_id(new_h4, "test_id3") ||
121 !ENGINE_set_name(new_h4, "Fourth test item")) 116 !ENGINE_set_name(new_h4, "Fourth test item")) {
122 {
123 printf("Couldn't set up test ENGINE structures\n"); 117 printf("Couldn't set up test ENGINE structures\n");
124 goto end; 118 goto end;
125 } 119 }
120
126 printf("\nenginetest beginning\n\n"); 121 printf("\nenginetest beginning\n\n");
127 display_engine_list(); 122 display_engine_list();
128 if(!ENGINE_add(new_h1)) 123 if (!ENGINE_add(new_h1)) {
129 {
130 printf("Add failed!\n"); 124 printf("Add failed!\n");
131 goto end; 125 goto end;
132 } 126 }
133 display_engine_list(); 127 display_engine_list();
134 ptr = ENGINE_get_first(); 128 ptr = ENGINE_get_first();
135 if(!ENGINE_remove(ptr)) 129 if (!ENGINE_remove(ptr)) {
136 {
137 printf("Remove failed!\n"); 130 printf("Remove failed!\n");
138 goto end; 131 goto end;
139 } 132 }
140 if (ptr) 133 if (ptr)
141 ENGINE_free(ptr); 134 ENGINE_free(ptr);
142 display_engine_list(); 135 display_engine_list();
143 if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) 136 if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
144 {
145 printf("Add failed!\n"); 137 printf("Add failed!\n");
146 goto end; 138 goto end;
147 } 139 }
148 display_engine_list(); 140 display_engine_list();
149 if(!ENGINE_remove(new_h2)) 141 if (!ENGINE_remove(new_h2)) {
150 {
151 printf("Remove failed!\n"); 142 printf("Remove failed!\n");
152 goto end; 143 goto end;
153 } 144 }
154 display_engine_list(); 145 display_engine_list();
155 if(!ENGINE_add(new_h4)) 146 if (!ENGINE_add(new_h4)) {
156 {
157 printf("Add failed!\n"); 147 printf("Add failed!\n");
158 goto end; 148 goto end;
159 } 149 }
160 display_engine_list(); 150 display_engine_list();
161 if(ENGINE_add(new_h3)) 151 if (ENGINE_add(new_h3)) {
162 {
163 printf("Add *should* have failed but didn't!\n"); 152 printf("Add *should* have failed but didn't!\n");
164 goto end; 153 goto end;
165 } 154 } else
166 else
167 printf("Add that should fail did.\n"); 155 printf("Add that should fail did.\n");
168 ERR_clear_error(); 156 ERR_clear_error();
169 if(ENGINE_remove(new_h2)) 157 if (ENGINE_remove(new_h2)) {
170 {
171 printf("Remove *should* have failed but didn't!\n"); 158 printf("Remove *should* have failed but didn't!\n");
172 goto end; 159 goto end;
173 } 160 } else
174 else
175 printf("Remove that should fail did.\n"); 161 printf("Remove that should fail did.\n");
176 ERR_clear_error(); 162 ERR_clear_error();
177 if(!ENGINE_remove(new_h3)) 163 if (!ENGINE_remove(new_h3)) {
178 {
179 printf("Remove failed!\n"); 164 printf("Remove failed!\n");
180 goto end; 165 goto end;
181 } 166 }
182 display_engine_list(); 167 display_engine_list();
183 if(!ENGINE_remove(new_h4)) 168 if (!ENGINE_remove(new_h4)) {
184 {
185 printf("Remove failed!\n"); 169 printf("Remove failed!\n");
186 goto end; 170 goto end;
187 } 171 }
188 display_engine_list(); 172 display_engine_list();
189 /* Depending on whether there's any hardware support compiled 173 /*
190 * in, this remove may be destined to fail. */ 174 * Depending on whether there's any hardware support compiled
175 * in, this remove may be destined to fail.
176 */
191 ptr = ENGINE_get_first(); 177 ptr = ENGINE_get_first();
192 if(ptr) 178 if (ptr)
193 if(!ENGINE_remove(ptr)) 179 if (!ENGINE_remove(ptr))
194 printf("Remove failed!i - probably no hardware " 180 printf("Remove failed!i - probably no hardware "
195 "support present.\n"); 181 "support present.\n");
196 if (ptr) 182 if (ptr)
197 ENGINE_free(ptr); 183 ENGINE_free(ptr);
198 display_engine_list(); 184 display_engine_list();
199 if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) 185
200 { 186 if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
201 printf("Couldn't add and remove to an empty list!\n"); 187 printf("Couldn't add and remove to an empty list!\n");
202 goto end; 188 goto end;
203 } 189 } else
204 else
205 printf("Successfully added and removed to an empty list!\n"); 190 printf("Successfully added and removed to an empty list!\n");
191
206 printf("About to beef up the engine-type list\n"); 192 printf("About to beef up the engine-type list\n");
207 for(loop = 0; loop < 512; loop++) 193 for (loop = 0; loop < 512; loop++) {
208 { 194 if (asprintf(&id, "id%i", loop) == -1)
209 asprintf(&id, "id%i", loop); 195 goto end;
210 asprintf(&name, "Fake engine type %i", loop); 196 if (asprintf(&name, "Fake engine type %i", loop) == -1)
211 if(((block[loop] = ENGINE_new()) == NULL) || 197 goto end;
212 !id || !ENGINE_set_id(block[loop], id) || 198
213 !name || !ENGINE_set_name(block[loop], name)) 199 if (((block[loop] = ENGINE_new()) == NULL) ||
214 { 200 !id || !ENGINE_set_id(block[loop], id) ||
215 printf("Couldn't create block of ENGINE structures.\n" 201 !name || !ENGINE_set_name(block[loop], name)) {
216 "I'll probably also core-dump now, damn.\n"); 202 printf("Couldn't create block of ENGINE structures.\n");
217 goto end; 203 goto end;
218 }
219 } 204 }
220 for(loop = 0; loop < 512; loop++) 205 }
221 { 206
222 if(!ENGINE_add(block[loop])) 207 for (loop = 0; loop < 512; loop++) {
223 { 208 if (!ENGINE_add(block[loop])) {
224 printf("\nAdding stopped at %i, (%s,%s)\n", 209 printf("\nAdding stopped at %i, (%s,%s)\n",
225 loop, ENGINE_get_id(block[loop]), 210 loop, ENGINE_get_id(block[loop]),
226 ENGINE_get_name(block[loop])); 211 ENGINE_get_name(block[loop]));
227 goto cleanup_loop; 212 goto cleanup_loop;
228 } 213 } else
229 else
230 printf("."); fflush(stdout); 214 printf("."); fflush(stdout);
231 } 215 }
232cleanup_loop: 216cleanup_loop:
233 printf("\nAbout to empty the engine-type list\n"); 217 printf("\nAbout to empty the engine-type list\n");
234 while((ptr = ENGINE_get_first()) != NULL) 218 while ((ptr = ENGINE_get_first()) != NULL) {
235 { 219 if (!ENGINE_remove(ptr)) {
236 if(!ENGINE_remove(ptr))
237 {
238 printf("\nRemove failed!\n"); 220 printf("\nRemove failed!\n");
239 goto end; 221 goto end;
240 } 222 }
241 ENGINE_free(ptr); 223 ENGINE_free(ptr);
242 printf("."); fflush(stdout); 224 printf("."); fflush(stdout);
243 } 225 }
244 for(loop = 0; loop < 512; loop++) 226 for (loop = 0; loop < 512; loop++) {
245 {
246 free((void *)ENGINE_get_id(block[loop])); 227 free((void *)ENGINE_get_id(block[loop]));
247 free((void *)ENGINE_get_name(block[loop])); 228 free((void *)ENGINE_get_name(block[loop]));
248 } 229 }
249 printf("\nTests completed happily\n"); 230 printf("\nTests completed happily\n");
250 to_return = 0; 231 to_return = 0;
251end: 232end:
252 if(to_return) 233 if (to_return)
253 ERR_print_errors_fp(stderr); 234 ERR_print_errors_fp(stderr);
254 if(new_h1) ENGINE_free(new_h1); 235 if (new_h1) ENGINE_free(new_h1);
255 if(new_h2) ENGINE_free(new_h2); 236 if (new_h2) ENGINE_free(new_h2);
256 if(new_h3) ENGINE_free(new_h3); 237 if (new_h3) ENGINE_free(new_h3);
257 if(new_h4) ENGINE_free(new_h4); 238 if (new_h4) ENGINE_free(new_h4);
258 for(loop = 0; loop < 512; loop++) 239 for (loop = 0; loop < 512; loop++)
259 if(block[loop]) 240 if (block[loop])
260 ENGINE_free(block[loop]); 241 ENGINE_free(block[loop]);
261 ENGINE_cleanup(); 242 ENGINE_cleanup();
262 CRYPTO_cleanup_all_ex_data(); 243 CRYPTO_cleanup_all_ex_data();
@@ -264,5 +245,4 @@ end:
264 ERR_remove_thread_state(NULL); 245 ERR_remove_thread_state(NULL);
265 CRYPTO_mem_leaks_fp(stderr); 246 CRYPTO_mem_leaks_fp(stderr);
266 return to_return; 247 return to_return;
267 } 248}
268#endif