diff options
author | tb <> | 2023-09-05 14:59:00 +0000 |
---|---|---|
committer | tb <> | 2023-09-05 14:59:00 +0000 |
commit | 7e2eed9aad34ceb1fe6be665c6ac8c8f862f3ea2 (patch) | |
tree | 22da69dcececfe6528bc1a64fc0198f16e0c9897 /src/lib | |
parent | 19bc61edd255de4fdb63f93e51a2fc4806d43588 (diff) | |
download | openbsd-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.c | 20 |
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 | } |
209 | static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ) | 209 | static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ) |
210 | 210 | ||
211 | static int | ||
212 | init_added(void) | ||
213 | { | ||
214 | if (added != NULL) | ||
215 | return (1); | ||
216 | added = lh_ADDED_OBJ_new(); | ||
217 | return (added != NULL); | ||
218 | } | ||
219 | |||
220 | static void | 211 | static void |
221 | cleanup1_doall(ADDED_OBJ *a) | 212 | cleanup1_doall(ADDED_OBJ *a) |
222 | { | 213 | { |
@@ -289,13 +280,16 @@ LCRYPTO_ALIAS(OBJ_new_nid); | |||
289 | int | 280 | int |
290 | OBJ_add_object(const ASN1_OBJECT *obj) | 281 | OBJ_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)))) |