diff options
author | tb <> | 2023-12-14 14:01:42 +0000 |
---|---|---|
committer | tb <> | 2023-12-14 14:01:42 +0000 |
commit | 328833ccd96cfb7a5e2eac21582ffb6cbba6f312 (patch) | |
tree | f28cbdb9303b8f8d3bf5dcb9036e955e71fe4366 | |
parent | 12a7c59c2985d4787deb1a503da3768c45dd7b22 (diff) | |
download | openbsd-328833ccd96cfb7a5e2eac21582ffb6cbba6f312.tar.gz openbsd-328833ccd96cfb7a5e2eac21582ffb6cbba6f312.tar.bz2 openbsd-328833ccd96cfb7a5e2eac21582ffb6cbba6f312.zip |
Simplify OBJ_nid2ln()
If nid is in the range of built-in NIDs, return the corresponding
long name, unless some genius left a hole. Otherwise perform a yolo
check if there are any user-added objects with matching nid in the
global hash.
This changes behavior in that we now push an OBJ_R_UNKNOWN_NID error
onto the stack even if there are no user-added objects.
ok jsing
-rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 14da51645d..505de360fb 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.65 2023/12/13 23:34:45 tb Exp $ */ | 1 | /* $OpenBSD: obj_dat.c,v 1.66 2023/12/14 14:01:42 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 | * |
@@ -337,31 +337,34 @@ OBJ_nid2sn(int n) | |||
337 | LCRYPTO_ALIAS(OBJ_nid2sn); | 337 | LCRYPTO_ALIAS(OBJ_nid2sn); |
338 | 338 | ||
339 | const char * | 339 | const char * |
340 | OBJ_nid2ln(int n) | 340 | OBJ_nid2ln(int nid) |
341 | { | 341 | { |
342 | ADDED_OBJ ad, *adp; | 342 | if (nid >= 0 && nid < NUM_NID) { |
343 | ASN1_OBJECT ob; | 343 | if (nid == NID_undef || nid_objs[nid].nid != NID_undef) |
344 | return nid_objs[nid].ln; | ||
344 | 345 | ||
345 | if ((n >= 0) && (n < NUM_NID)) { | 346 | goto unknown; |
346 | if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { | 347 | } |
347 | OBJerror(OBJ_R_UNKNOWN_NID); | 348 | |
348 | return (NULL); | 349 | /* XXX - locking. */ |
349 | } | 350 | if (added != NULL) { |
350 | return (nid_objs[n].ln); | 351 | ASN1_OBJECT aobj = { |
351 | } else if (added == NULL) | 352 | .nid = nid, |
352 | return (NULL); | 353 | }; |
353 | else { | 354 | ADDED_OBJ needle = { |
354 | ad.type = ADDED_NID; | 355 | .type = ADDED_NID, |
355 | ad.obj = &ob; | 356 | .obj = &aobj, |
356 | ob.nid = n; | 357 | }; |
357 | adp = lh_ADDED_OBJ_retrieve(added, &ad); | 358 | ADDED_OBJ *found; |
358 | if (adp != NULL) | 359 | |
359 | return (adp->obj->ln); | 360 | if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL) |
360 | else { | 361 | return found->obj->ln; |
361 | OBJerror(OBJ_R_UNKNOWN_NID); | ||
362 | return (NULL); | ||
363 | } | ||
364 | } | 362 | } |
363 | |||
364 | unknown: | ||
365 | OBJerror(OBJ_R_UNKNOWN_NID); | ||
366 | |||
367 | return NULL; | ||
365 | } | 368 | } |
366 | LCRYPTO_ALIAS(OBJ_nid2ln); | 369 | LCRYPTO_ALIAS(OBJ_nid2ln); |
367 | 370 | ||