summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-09-05 14:59:00 +0000
committertb <>2023-09-05 14:59:00 +0000
commit7e2eed9aad34ceb1fe6be665c6ac8c8f862f3ea2 (patch)
tree22da69dcececfe6528bc1a64fc0198f16e0c9897 /src/lib
parent19bc61edd255de4fdb63f93e51a2fc4806d43588 (diff)
downloadopenbsd-7e2eed9aad34ceb1fe6be665c6ac8c8f862f3ea2.tar.gz
openbsd-7e2eed9aad34ceb1fe6be665c6ac8c8f862f3ea2.tar.bz2
openbsd-7e2eed9aad34ceb1fe6be665c6ac8c8f862f3ea2.zip
Improve error handling in OBJ_add_object()
There is no need for a helper function to obfuscate lh_ADDED_OBJ_new(). Just call the real thing directly. Adding an object with a NID of NID_undef basically amounts to disabling a built-in OID. It does so in an incoherent fashion and the caller can't easily tell success from failure of the operation. Arguably the result is a corrupted objects table. Let's not allow adding such an object in an attempt at keeping things slightly more coherent. Issue noted and initial diff by schwarze while writing documentation ok schwarze
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 9c4c3179f3..6cfbf8f773 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_dat.c,v 1.60 2023/08/17 09:28:43 tb Exp $ */ 1/* $OpenBSD: obj_dat.c,v 1.61 2023/09/05 14:59:00 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -208,15 +208,6 @@ added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
208} 208}
209static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ) 209static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
210 210
211static int
212init_added(void)
213{
214 if (added != NULL)
215 return (1);
216 added = lh_ADDED_OBJ_new();
217 return (added != NULL);
218}
219
220static void 211static void
221cleanup1_doall(ADDED_OBJ *a) 212cleanup1_doall(ADDED_OBJ *a)
222{ 213{
@@ -289,13 +280,16 @@ LCRYPTO_ALIAS(OBJ_new_nid);
289int 280int
290OBJ_add_object(const ASN1_OBJECT *obj) 281OBJ_add_object(const ASN1_OBJECT *obj)
291{ 282{
292 ASN1_OBJECT *o; 283 ASN1_OBJECT *o = NULL;
293 ADDED_OBJ *ao[4] = {NULL, NULL, NULL, NULL}, *aop; 284 ADDED_OBJ *ao[4] = {NULL, NULL, NULL, NULL}, *aop;
294 int i; 285 int i;
295 286
296 if (added == NULL) 287 if (added == NULL)
297 if (!init_added()) 288 added = lh_ADDED_OBJ_new();
298 return (0); 289 if (added == NULL)
290 goto err;
291 if (obj == NULL || obj->nid == NID_undef)
292 goto err;
299 if ((o = OBJ_dup(obj)) == NULL) 293 if ((o = OBJ_dup(obj)) == NULL)
300 goto err; 294 goto err;
301 if (!(ao[ADDED_NID] = malloc(sizeof(ADDED_OBJ)))) 295 if (!(ao[ADDED_NID] = malloc(sizeof(ADDED_OBJ))))