summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dso/dso_lib.c
diff options
context:
space:
mode:
authorbeck <>2017-01-29 17:49:23 +0000
committerbeck <>2017-01-29 17:49:23 +0000
commit957b11334a7afb14537322f0e4795b2e368b3f59 (patch)
tree1a54abba678898ee5270ae4f3404a50ee9a92eea /src/lib/libcrypto/dso/dso_lib.c
parentdf96e020e729c6c37a8c7fe311fdd1fe6a8718c5 (diff)
downloadopenbsd-957b11334a7afb14537322f0e4795b2e368b3f59.tar.gz
openbsd-957b11334a7afb14537322f0e4795b2e368b3f59.tar.bz2
openbsd-957b11334a7afb14537322f0e4795b2e368b3f59.zip
Send the function codes from the error functions to the bit bucket,
as was done earlier in libssl. Thanks inoguchi@ for noticing libssl had more reacharounds into this. ok jsing@ inoguchi@
Diffstat (limited to 'src/lib/libcrypto/dso/dso_lib.c')
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
index 3002e4d99c..7902fbcc6e 100644
--- a/src/lib/libcrypto/dso/dso_lib.c
+++ b/src/lib/libcrypto/dso/dso_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dso_lib.c,v 1.18 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dso_lib.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -111,13 +111,13 @@ DSO_new_method(DSO_METHOD *meth)
111 default_DSO_meth = DSO_METHOD_openssl(); 111 default_DSO_meth = DSO_METHOD_openssl();
112 ret = calloc(1, sizeof(DSO)); 112 ret = calloc(1, sizeof(DSO));
113 if (ret == NULL) { 113 if (ret == NULL) {
114 DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); 114 DSOerror(ERR_R_MALLOC_FAILURE);
115 return (NULL); 115 return (NULL);
116 } 116 }
117 ret->meth_data = sk_void_new_null(); 117 ret->meth_data = sk_void_new_null();
118 if (ret->meth_data == NULL) { 118 if (ret->meth_data == NULL) {
119 /* sk_new doesn't generate any errors so we do */ 119 /* sk_new doesn't generate any errors so we do */
120 DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); 120 DSOerror(ERR_R_MALLOC_FAILURE);
121 free(ret); 121 free(ret);
122 return (NULL); 122 return (NULL);
123 } 123 }
@@ -139,7 +139,7 @@ DSO_free(DSO *dso)
139 int i; 139 int i;
140 140
141 if (dso == NULL) { 141 if (dso == NULL) {
142 DSOerr(DSO_F_DSO_FREE, ERR_R_PASSED_NULL_PARAMETER); 142 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
143 return (0); 143 return (0);
144 } 144 }
145 145
@@ -148,12 +148,12 @@ DSO_free(DSO *dso)
148 return (1); 148 return (1);
149 149
150 if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) { 150 if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
151 DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED); 151 DSOerror(DSO_R_UNLOAD_FAILED);
152 return (0); 152 return (0);
153 } 153 }
154 154
155 if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) { 155 if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
156 DSOerr(DSO_F_DSO_FREE, DSO_R_FINISH_FAILED); 156 DSOerror(DSO_R_FINISH_FAILED);
157 return (0); 157 return (0);
158 } 158 }
159 159
@@ -175,7 +175,7 @@ int
175DSO_up_ref(DSO *dso) 175DSO_up_ref(DSO *dso)
176{ 176{
177 if (dso == NULL) { 177 if (dso == NULL) {
178 DSOerr(DSO_F_DSO_UP_REF, ERR_R_PASSED_NULL_PARAMETER); 178 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
179 return (0); 179 return (0);
180 } 180 }
181 181
@@ -192,40 +192,40 @@ DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
192 if (dso == NULL) { 192 if (dso == NULL) {
193 ret = DSO_new_method(meth); 193 ret = DSO_new_method(meth);
194 if (ret == NULL) { 194 if (ret == NULL) {
195 DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE); 195 DSOerror(ERR_R_MALLOC_FAILURE);
196 goto err; 196 goto err;
197 } 197 }
198 allocated = 1; 198 allocated = 1;
199 /* Pass the provided flags to the new DSO object */ 199 /* Pass the provided flags to the new DSO object */
200 if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) { 200 if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) {
201 DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED); 201 DSOerror(DSO_R_CTRL_FAILED);
202 goto err; 202 goto err;
203 } 203 }
204 } else 204 } else
205 ret = dso; 205 ret = dso;
206 /* Don't load if we're currently already loaded */ 206 /* Don't load if we're currently already loaded */
207 if (ret->filename != NULL) { 207 if (ret->filename != NULL) {
208 DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED); 208 DSOerror(DSO_R_DSO_ALREADY_LOADED);
209 goto err; 209 goto err;
210 } 210 }
211 /* filename can only be NULL if we were passed a dso that already has 211 /* filename can only be NULL if we were passed a dso that already has
212 * one set. */ 212 * one set. */
213 if (filename != NULL) 213 if (filename != NULL)
214 if (!DSO_set_filename(ret, filename)) { 214 if (!DSO_set_filename(ret, filename)) {
215 DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED); 215 DSOerror(DSO_R_SET_FILENAME_FAILED);
216 goto err; 216 goto err;
217 } 217 }
218 filename = ret->filename; 218 filename = ret->filename;
219 if (filename == NULL) { 219 if (filename == NULL) {
220 DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME); 220 DSOerror(DSO_R_NO_FILENAME);
221 goto err; 221 goto err;
222 } 222 }
223 if (ret->meth->dso_load == NULL) { 223 if (ret->meth->dso_load == NULL) {
224 DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED); 224 DSOerror(DSO_R_UNSUPPORTED);
225 goto err; 225 goto err;
226 } 226 }
227 if (!ret->meth->dso_load(ret)) { 227 if (!ret->meth->dso_load(ret)) {
228 DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED); 228 DSOerror(DSO_R_LOAD_FAILED);
229 goto err; 229 goto err;
230 } 230 }
231 /* Load succeeded */ 231 /* Load succeeded */
@@ -243,15 +243,15 @@ DSO_bind_var(DSO *dso, const char *symname)
243 void *ret = NULL; 243 void *ret = NULL;
244 244
245 if ((dso == NULL) || (symname == NULL)) { 245 if ((dso == NULL) || (symname == NULL)) {
246 DSOerr(DSO_F_DSO_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER); 246 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
247 return (NULL); 247 return (NULL);
248 } 248 }
249 if (dso->meth->dso_bind_var == NULL) { 249 if (dso->meth->dso_bind_var == NULL) {
250 DSOerr(DSO_F_DSO_BIND_VAR, DSO_R_UNSUPPORTED); 250 DSOerror(DSO_R_UNSUPPORTED);
251 return (NULL); 251 return (NULL);
252 } 252 }
253 if ((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) { 253 if ((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) {
254 DSOerr(DSO_F_DSO_BIND_VAR, DSO_R_SYM_FAILURE); 254 DSOerror(DSO_R_SYM_FAILURE);
255 return (NULL); 255 return (NULL);
256 } 256 }
257 /* Success */ 257 /* Success */
@@ -264,15 +264,15 @@ DSO_bind_func(DSO *dso, const char *symname)
264 DSO_FUNC_TYPE ret = NULL; 264 DSO_FUNC_TYPE ret = NULL;
265 265
266 if ((dso == NULL) || (symname == NULL)) { 266 if ((dso == NULL) || (symname == NULL)) {
267 DSOerr(DSO_F_DSO_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER); 267 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
268 return (NULL); 268 return (NULL);
269 } 269 }
270 if (dso->meth->dso_bind_func == NULL) { 270 if (dso->meth->dso_bind_func == NULL) {
271 DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_UNSUPPORTED); 271 DSOerror(DSO_R_UNSUPPORTED);
272 return (NULL); 272 return (NULL);
273 } 273 }
274 if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) { 274 if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) {
275 DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_SYM_FAILURE); 275 DSOerror(DSO_R_SYM_FAILURE);
276 return (NULL); 276 return (NULL);
277 } 277 }
278 /* Success */ 278 /* Success */
@@ -291,7 +291,7 @@ long
291DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) 291DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
292{ 292{
293 if (dso == NULL) { 293 if (dso == NULL) {
294 DSOerr(DSO_F_DSO_CTRL, ERR_R_PASSED_NULL_PARAMETER); 294 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
295 return (-1); 295 return (-1);
296 } 296 }
297 /* We should intercept certain generic commands and only pass control 297 /* We should intercept certain generic commands and only pass control
@@ -310,7 +310,7 @@ DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
310 break; 310 break;
311 } 311 }
312 if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) { 312 if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) {
313 DSOerr(DSO_F_DSO_CTRL, DSO_R_UNSUPPORTED); 313 DSOerror(DSO_R_UNSUPPORTED);
314 return (-1); 314 return (-1);
315 } 315 }
316 return (dso->meth->dso_ctrl(dso, cmd, larg, parg)); 316 return (dso->meth->dso_ctrl(dso, cmd, larg, parg));
@@ -321,8 +321,7 @@ DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
321 DSO_NAME_CONVERTER_FUNC *oldcb) 321 DSO_NAME_CONVERTER_FUNC *oldcb)
322{ 322{
323 if (dso == NULL) { 323 if (dso == NULL) {
324 DSOerr(DSO_F_DSO_SET_NAME_CONVERTER, 324 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
325 ERR_R_PASSED_NULL_PARAMETER);
326 return (0); 325 return (0);
327 } 326 }
328 if (oldcb) 327 if (oldcb)
@@ -335,7 +334,7 @@ const char *
335DSO_get_filename(DSO *dso) 334DSO_get_filename(DSO *dso)
336{ 335{
337 if (dso == NULL) { 336 if (dso == NULL) {
338 DSOerr(DSO_F_DSO_GET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); 337 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
339 return (NULL); 338 return (NULL);
340 } 339 }
341 return (dso->filename); 340 return (dso->filename);
@@ -347,17 +346,17 @@ DSO_set_filename(DSO *dso, const char *filename)
347 char *copied; 346 char *copied;
348 347
349 if ((dso == NULL) || (filename == NULL)) { 348 if ((dso == NULL) || (filename == NULL)) {
350 DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); 349 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
351 return (0); 350 return (0);
352 } 351 }
353 if (dso->loaded_filename) { 352 if (dso->loaded_filename) {
354 DSOerr(DSO_F_DSO_SET_FILENAME, DSO_R_DSO_ALREADY_LOADED); 353 DSOerror(DSO_R_DSO_ALREADY_LOADED);
355 return (0); 354 return (0);
356 } 355 }
357 /* We'll duplicate filename */ 356 /* We'll duplicate filename */
358 copied = strdup(filename); 357 copied = strdup(filename);
359 if (copied == NULL) { 358 if (copied == NULL) {
360 DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); 359 DSOerror(ERR_R_MALLOC_FAILURE);
361 return (0); 360 return (0);
362 } 361 }
363 free(dso->filename); 362 free(dso->filename);
@@ -371,7 +370,7 @@ DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
371 char *result = NULL; 370 char *result = NULL;
372 371
373 if (dso == NULL || filespec1 == NULL) { 372 if (dso == NULL || filespec1 == NULL) {
374 DSOerr(DSO_F_DSO_MERGE, ERR_R_PASSED_NULL_PARAMETER); 373 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
375 return (NULL); 374 return (NULL);
376 } 375 }
377 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { 376 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
@@ -390,13 +389,13 @@ DSO_convert_filename(DSO *dso, const char *filename)
390 char *result = NULL; 389 char *result = NULL;
391 390
392 if (dso == NULL) { 391 if (dso == NULL) {
393 DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_PASSED_NULL_PARAMETER); 392 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
394 return (NULL); 393 return (NULL);
395 } 394 }
396 if (filename == NULL) 395 if (filename == NULL)
397 filename = dso->filename; 396 filename = dso->filename;
398 if (filename == NULL) { 397 if (filename == NULL) {
399 DSOerr(DSO_F_DSO_CONVERT_FILENAME, DSO_R_NO_FILENAME); 398 DSOerror(DSO_R_NO_FILENAME);
400 return (NULL); 399 return (NULL);
401 } 400 }
402 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { 401 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
@@ -408,8 +407,7 @@ DSO_convert_filename(DSO *dso, const char *filename)
408 if (result == NULL) { 407 if (result == NULL) {
409 result = strdup(filename); 408 result = strdup(filename);
410 if (result == NULL) { 409 if (result == NULL) {
411 DSOerr(DSO_F_DSO_CONVERT_FILENAME, 410 DSOerror(ERR_R_MALLOC_FAILURE);
412 ERR_R_MALLOC_FAILURE);
413 return (NULL); 411 return (NULL);
414 } 412 }
415 } 413 }
@@ -420,8 +418,7 @@ const char *
420DSO_get_loaded_filename(DSO *dso) 418DSO_get_loaded_filename(DSO *dso)
421{ 419{
422 if (dso == NULL) { 420 if (dso == NULL) {
423 DSOerr(DSO_F_DSO_GET_LOADED_FILENAME, 421 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
424 ERR_R_PASSED_NULL_PARAMETER);
425 return (NULL); 422 return (NULL);
426 } 423 }
427 return (dso->loaded_filename); 424 return (dso->loaded_filename);
@@ -434,7 +431,7 @@ DSO_pathbyaddr(void *addr, char *path, int sz)
434 if (meth == NULL) 431 if (meth == NULL)
435 meth = DSO_METHOD_openssl(); 432 meth = DSO_METHOD_openssl();
436 if (meth->pathbyaddr == NULL) { 433 if (meth->pathbyaddr == NULL) {
437 DSOerr(DSO_F_DSO_PATHBYADDR, DSO_R_UNSUPPORTED); 434 DSOerror(DSO_R_UNSUPPORTED);
438 return -1; 435 return -1;
439 } 436 }
440 return (*meth->pathbyaddr)(addr, path, sz); 437 return (*meth->pathbyaddr)(addr, path, sz);
@@ -447,7 +444,7 @@ DSO_global_lookup(const char *name)
447 if (meth == NULL) 444 if (meth == NULL)
448 meth = DSO_METHOD_openssl(); 445 meth = DSO_METHOD_openssl();
449 if (meth->globallookup == NULL) { 446 if (meth->globallookup == NULL) {
450 DSOerr(DSO_F_DSO_GLOBAL_LOOKUP, DSO_R_UNSUPPORTED); 447 DSOerror(DSO_R_UNSUPPORTED);
451 return NULL; 448 return NULL;
452 } 449 }
453 return (*meth->globallookup)(name); 450 return (*meth->globallookup)(name);