From: Dr. David von Oheimb Date: Fri, 3 Dec 2021 16:58:26 +0000 (+0100) Subject: apps/cmp.c: improve print_itavs() X-Git-Tag: openssl-3.2.0-alpha1~2446 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9650648821aadabf2d9f3de321f344230b13a4a;p=thirdparty%2Fopenssl.git apps/cmp.c: improve print_itavs() Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: Hugo Landau (Merged from https://github.com/openssl/openssl/pull/18657) --- diff --git a/apps/cmp.c b/apps/cmp.c index a433f2b324a..25c32f69cd8 100644 --- a/apps/cmp.c +++ b/apps/cmp.c @@ -2047,28 +2047,35 @@ static int save_free_certs(OSSL_CMP_CTX *ctx, return n; } -static void print_itavs(STACK_OF(OSSL_CMP_ITAV) *itavs) +static int print_itavs(const STACK_OF(OSSL_CMP_ITAV) *itavs) { - OSSL_CMP_ITAV *itav = NULL; - char buf[128]; - int i, r; - int n = sk_OSSL_CMP_ITAV_num(itavs); /* itavs == NULL leads to 0 */ + int i, ret = 1; + int n = sk_OSSL_CMP_ITAV_num(itavs); - if (n == 0) { - CMP_info("genp contains no ITAV"); - return; + if (n <= 0) { /* also in case itavs == NULL */ + CMP_info("genp does not contain any ITAV"); + return ret; } - for (i = 0; i < n; i++) { - itav = sk_OSSL_CMP_ITAV_value(itavs, i); - r = OBJ_obj2txt(buf, 128, OSSL_CMP_ITAV_get0_type(itav), 0); - if (r < 0) - CMP_err("could not get ITAV details"); - else if (r == 0) - CMP_info("genp contains empty ITAV"); - else - CMP_info1("genp contains ITAV of type: %s", buf); + for (i = 1; i <= n; i++) { + OSSL_CMP_ITAV *itav = sk_OSSL_CMP_ITAV_value(itavs, i - 1); + ASN1_OBJECT *type = OSSL_CMP_ITAV_get0_type(itav); + char name[80]; + + if (itav == NULL) { + CMP_err1("could not get ITAV #%d from genp", i); + ret = 0; + continue; + } + if (i2t_ASN1_OBJECT(name, sizeof(name), type) <= 0) { + CMP_err1("error parsing type of ITAV #%d from genp", i); + ret = 0; + } + else { + CMP_info2("ITAV #%d from genp type=%s", i, name); + } } + return ret; } static char opt_item[SECTION_NAME_MAX + 1]; @@ -2942,9 +2949,10 @@ int cmp_main(int argc, char **argv) } if ((itavs = OSSL_CMP_exec_GENM_ses(cmp_ctx)) != NULL) { - print_itavs(itavs); + ret = print_itavs(itavs); sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free); - ret = 1; + } else { + CMP_err("could not obtain ITAVs from genp"); } break; }