diff options
author | Hugo Landau <hlandau@openssl.org> | 2022-03-03 17:27:23 +0000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2022-03-11 13:30:22 +1100 |
commit | add8c29badb315cb8137655893826562ff12a581 (patch) | |
tree | 3de7cb5097e4f277bac157c4e814f083956ae721 | |
parent | 3aeed22c593ae036c2503ac07276768c82fe5782 (diff) |
Fix issue where OBJ_nid2obj doesn't always raise an error
This was previously fixed in 3.0 but not 1.1.
Fixes #13008.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17808)
-rw-r--r-- | crypto/objects/obj_dat.c | 5 | ||||
-rw-r--r-- | test/asn1_internal_test.c | 27 |
2 files changed, 30 insertions, 2 deletions
diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index 46006fe6cf..a501ca104b 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -228,9 +228,10 @@ ASN1_OBJECT *OBJ_nid2obj(int n) return NULL; } return (ASN1_OBJECT *)&(nid_objs[n]); - } else if (added == NULL) + } else if (added == NULL) { + OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID); return NULL; - else { + } else { ad.type = ADDED_NID; ad.obj = &ob; ob.nid = n; diff --git a/test/asn1_internal_test.c b/test/asn1_internal_test.c index 865e058421..caca0cb15e 100644 --- a/test/asn1_internal_test.c +++ b/test/asn1_internal_test.c @@ -107,9 +107,36 @@ static int test_standard_methods(void) return 0; } +/********************************************************************** + * + * Regression test for issue where OBJ_nid2obj does not raise + * an error when a NID is not registered. + * + ***/ +static int test_nid2obj_nonexist(void) +{ + ASN1_OBJECT *obj; + unsigned long err; + + obj = OBJ_nid2obj(INT_MAX); + if (!TEST_true(obj == NULL)) + return 0; + + err = ERR_get_error(); + + if (!TEST_int_eq(ERR_GET_FUNC(err), OBJ_F_OBJ_NID2OBJ)) + return 0; + + if (!TEST_int_eq(ERR_GET_REASON(err), OBJ_R_UNKNOWN_NID)) + return 0; + + return 1; +} + int setup_tests(void) { ADD_TEST(test_tbl_standard); ADD_TEST(test_standard_methods); + ADD_TEST(test_nid2obj_nonexist); return 1; } |