From a4c467c96aeae3d52e2f16b8b829749ed6c55fe7 Mon Sep 17 00:00:00 2001 From: David von Oheimb Date: Mon, 29 Jan 2018 16:54:40 +0100 Subject: [PATCH] remove needless empty lines when printing certificates Reviewed-by: Richard Levitte Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/6226) --- crypto/dsa/dsa_ameth.c | 2 ++ crypto/rsa/rsa_ameth.c | 2 +- crypto/x509/t_x509.c | 6 +++--- crypto/x509v3/v3_alt.c | 1 - crypto/x509v3/v3_cpols.c | 21 ++++++++++++++------- crypto/x509v3/v3_crld.c | 6 ++++-- crypto/x509v3/v3_ncons.c | 5 ++++- crypto/x509v3/v3_pci.c | 3 +-- crypto/x509v3/v3_prn.c | 7 ++++--- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index f28021d7b1..756ee7441d 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -458,6 +458,8 @@ static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, DSA_SIG_free(dsa_sig); return rv; } + if (BIO_puts(bp, "\n") <= 0) + return 0; return X509_signature_dump(bp, sig, indent); } diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index c6ae8a4535..139415e60e 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -447,7 +447,7 @@ static int rsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, RSA_PSS_PARAMS_free(pss); if (!rv) return 0; - } else if (!sig && BIO_puts(bp, "\n") <= 0) { + } else if (BIO_puts(bp, "\n") <= 0) { return 0; } if (sig) diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index 29e20939ec..fb367baa1e 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -284,7 +284,7 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) s = sig->data; for (i = 0; i < n; i++) { if ((i % 18) == 0) { - if (BIO_write(bp, "\n", 1) <= 0) + if (i > 0 && BIO_write(bp, "\n", 1) <= 0) return 0; if (BIO_indent(bp, indent, indent) <= 0) return 0; @@ -317,10 +317,10 @@ int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, return ameth->sig_print(bp, sigalg, sig, 9, 0); } } + if (BIO_write(bp, "\n", 1) != 1) + return 0; if (sig) return X509_signature_dump(bp, sig, 9); - else if (BIO_puts(bp, "\n") <= 0) - return 0; return 1; } diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c index 128c68b5f1..9b627e071c 100644 --- a/crypto/x509v3/v3_alt.c +++ b/crypto/x509v3/v3_alt.c @@ -183,7 +183,6 @@ int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen) BIO_printf(out, ":%X", p[0] << 8 | p[1]); p += 2; } - BIO_puts(out, "\n"); } else { BIO_printf(out, "IP Address:"); break; diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c index bfdaf0acec..595de62361 100644 --- a/crypto/x509v3/v3_cpols.c +++ b/crypto/x509v3/v3_cpols.c @@ -403,12 +403,15 @@ static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, POLICYINFO *pinfo; /* First print out the policy OIDs */ for (i = 0; i < sk_POLICYINFO_num(pol); i++) { + if (i > 0) + BIO_puts(out, "\n"); pinfo = sk_POLICYINFO_value(pol, i); BIO_printf(out, "%*sPolicy: ", indent, ""); i2a_ASN1_OBJECT(out, pinfo->policyid); - BIO_puts(out, "\n"); - if (pinfo->qualifiers) + if (pinfo->qualifiers) { + BIO_puts(out, "\n"); print_qualifiers(out, pinfo->qualifiers, indent + 2); + } } return 1; } @@ -419,10 +422,12 @@ static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, POLICYQUALINFO *qualinfo; int i; for (i = 0; i < sk_POLICYQUALINFO_num(quals); i++) { + if (i > 0) + BIO_puts(out, "\n"); qualinfo = sk_POLICYQUALINFO_value(quals, i); switch (OBJ_obj2nid(qualinfo->pqualid)) { case NID_id_qt_cps: - BIO_printf(out, "%*sCPS: %s\n", indent, "", + BIO_printf(out, "%*sCPS: %s", indent, "", qualinfo->d.cpsuri->data); break; @@ -435,7 +440,6 @@ static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, BIO_printf(out, "%*sUnknown Qualifier: ", indent + 2, ""); i2a_ASN1_OBJECT(out, qualinfo->pqualid); - BIO_puts(out, "\n"); break; } } @@ -467,10 +471,11 @@ static void print_notice(BIO *out, USERNOTICE *notice, int indent) OPENSSL_free(tmp); } } - BIO_puts(out, "\n"); + if (notice->exptext) + BIO_puts(out, "\n"); } if (notice->exptext) - BIO_printf(out, "%*sExplicit Text: %s\n", indent, "", + BIO_printf(out, "%*sExplicit Text: %s", indent, "", notice->exptext->data); } @@ -484,8 +489,10 @@ void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent) BIO_puts(out, "\n"); BIO_printf(out, "%*s%s\n", indent + 2, "", node_data_critical(dat) ? "Critical" : "Non Critical"); - if (dat->qualifier_set) + if (dat->qualifier_set) { print_qualifiers(out, dat->qualifier_set, indent + 2); + BIO_puts(out, "\n"); + } else BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, ""); } diff --git a/crypto/x509v3/v3_crld.c b/crypto/x509v3/v3_crld.c index 5d290acbab..766bf0e5c8 100644 --- a/crypto/x509v3/v3_crld.c +++ b/crypto/x509v3/v3_crld.c @@ -410,9 +410,10 @@ static int print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent) { int i; for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { + if (i > 0) + BIO_puts(out, "\n"); BIO_printf(out, "%*s", indent + 2, ""); GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i)); - BIO_puts(out, "\n"); } return 1; } @@ -463,7 +464,8 @@ static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, DIST_POINT *point; int i; for (i = 0; i < sk_DIST_POINT_num(crld); i++) { - BIO_puts(out, "\n"); + if (i > 0) + BIO_puts(out, "\n"); point = sk_DIST_POINT_value(crld, i); if (point->distpoint) print_distpoint(out, point->distpoint, indent); diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c index d16c6eeb0f..9a8ca16685 100644 --- a/crypto/x509v3/v3_ncons.c +++ b/crypto/x509v3/v3_ncons.c @@ -158,6 +158,8 @@ static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *a, NAME_CONSTRAINTS *ncons = a; do_i2r_name_constraints(method, ncons->permittedSubtrees, bp, ind, "Permitted"); + if (ncons->permittedSubtrees && ncons->excludedSubtrees) + BIO_puts(bp, "\n"); do_i2r_name_constraints(method, ncons->excludedSubtrees, bp, ind, "Excluded"); return 1; @@ -172,13 +174,14 @@ static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method, if (sk_GENERAL_SUBTREE_num(trees) > 0) BIO_printf(bp, "%*s%s:\n", ind, "", name); for (i = 0; i < sk_GENERAL_SUBTREE_num(trees); i++) { + if (i > 0) + BIO_puts(bp, "\n"); tree = sk_GENERAL_SUBTREE_value(trees, i); BIO_printf(bp, "%*s", ind + 2, ""); if (tree->base->type == GEN_IPADD) print_nc_ipadd(bp, tree->base->d.ip); else GENERAL_NAME_print(bp, tree->base); - BIO_puts(bp, "\n"); } return 1; } diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c index c0c599bfeb..856b70d9b5 100644 --- a/crypto/x509v3/v3_pci.c +++ b/crypto/x509v3/v3_pci.c @@ -75,9 +75,8 @@ static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci, BIO_puts(out, "\n"); BIO_printf(out, "%*sPolicy Language: ", indent, ""); i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage); - BIO_puts(out, "\n"); if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data) - BIO_printf(out, "%*sPolicy Text: %s\n", indent, "", + BIO_printf(out, "\n%*sPolicy Text: %s", indent, "", pci->proxyPolicy->policy->data); return 1; } diff --git a/crypto/x509v3/v3_prn.c b/crypto/x509v3/v3_prn.c index 24e73a7ef3..2ef76c1b5b 100644 --- a/crypto/x509v3/v3_prn.c +++ b/crypto/x509v3/v3_prn.c @@ -34,8 +34,11 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, BIO_puts(out, "\n"); } for (i = 0; i < sk_CONF_VALUE_num(val); i++) { - if (ml) + if (ml) { + if (i > 0) + BIO_printf(out, "\n"); BIO_printf(out, "%*s", indent, ""); + } else if (i > 0) BIO_printf(out, ", "); nval = sk_CONF_VALUE_value(val, i); @@ -59,8 +62,6 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, } } #endif - if (ml) - BIO_puts(out, "\n"); } } -- 2.25.1