apps/x509.c:729: error: BUFFER_OVERRUN_L2
  Offset: [-oo, 1048576] Size: 256 by call to `X509_NAME_oneline`.
Showing all 6 steps of the trace


apps/x509.c:146:1: Array declaration
144.   };
145.   
146. > int x509_main(int argc, char **argv)
147.   {
148.       ASN1_INTEGER *sno = NULL;

apps/x509.c:729:17: Call
727.                   int len;
728.   
729.                   X509_NAME_oneline(X509_get_subject_name(x), buf, sizeof buf);
                       ^
730.                   BIO_printf(out, "/*\n"
731.                                   " * Subject: %s\n", buf);

crypto/x509/x509_obj.c:25:1: <Length trace>
23.   #define NAME_ONELINE_MAX    (1024 * 1024)
24.   
25. > char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
26.   {
27.       const X509_NAME_ENTRY *ne;

crypto/x509/x509_obj.c:25:1: Parameter `*buf`
  23.   #define NAME_ONELINE_MAX    (1024 * 1024)
  24.   
  25. > char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
  26.   {
  27.       const X509_NAME_ENTRY *ne;

crypto/x509/x509_obj.c:134:13: Assignment
  132.               break;
  133.           } else
  134.               p = &(buf[lold]);
                     ^
  135.           *(p++) = '/';
  136.           memcpy(p, s, (unsigned int)l1);

crypto/x509/x509_obj.c:135:9: Array access: Offset: [-oo, 1048576] Size: 256 by call to `X509_NAME_oneline` 
  133.           } else
  134.               p = &(buf[lold]);
  135.           *(p++) = '/';
                 ^
  136.           memcpy(p, s, (unsigned int)l1);
  137.           p += l1;

char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
{
    const X509_NAME_ENTRY *ne;
    int i;
    int n, lold, l, l1, l2, num, j, type;
    const char *s;
    char *p;
    unsigned char *q;
    BUF_MEM *b = NULL;
    static const char hex[17] = "0123456789ABCDEF";
    int gs_doit[4];
    char tmp_buf[80];
#ifdef CHARSET_EBCDIC
    unsigned char ebcdic_buf[1024];
#endif
    if (buf == NULL) {
        if ((b = BUF_MEM_new()) == NULL)
            goto err;
        if (!BUF_MEM_grow(b, 200))
            goto err;
        b->data[0] = '\0';
        len = 200;
    } else if (len == 0) {
        return NULL;
    }
    if (a == NULL) {
        if (b) {
            buf = b->data;
            OPENSSL_free(b);
        }
        strncpy(buf, "NO X509_NAME", len);
        buf[len - 1] = '\0';
        return buf;
    }
    len--;
    l = 0;
    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
        ne = sk_X509_NAME_ENTRY_value(a->entries, i);
        n = OBJ_obj2nid(ne->object);
        if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
            i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
            s = tmp_buf;
        }
        l1 = strlen(s);
        type = ne->value->type;
        num = ne->value->length;
        if (num > NAME_ONELINE_MAX) {
            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
            goto end;
        }
        q = ne->value->data;
#ifdef CHARSET_EBCDIC
        if (type == V_ASN1_GENERALSTRING ||
            type == V_ASN1_VISIBLESTRING ||
            type == V_ASN1_PRINTABLESTRING ||
            type == V_ASN1_TELETEXSTRING ||
            type == V_ASN1_IA5STRING) {
            if (num > (int)sizeof(ebcdic_buf))
                num = sizeof(ebcdic_buf);
            ascii2ebcdic(ebcdic_buf, q, num);
            q = ebcdic_buf;
        }
#endif
        if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
            for (j = 0; j < num; j++)
                if (q[j] != 0)
                    gs_doit[j & 3] = 1;
            if (gs_doit[0] | gs_doit[1] | gs_doit[2])
                gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
            else {
                gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
                gs_doit[3] = 1;
            }
        } else
            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
        for (l2 = j = 0; j < num; j++) {
            if (!gs_doit[j & 3])
                continue;
            l2++;
#ifndef CHARSET_EBCDIC
            if ((q[j] < ' ') || (q[j] > '~'))
                l2 += 3;
#else
            if ((os_toascii[q[j]] < os_toascii[' ']) ||
                (os_toascii[q[j]] > os_toascii['~']))
                l2 += 3;
#endif
        }
        lold = l;
        l += 1 + l1 + 1 + l2;
        if (l > NAME_ONELINE_MAX) {
            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
            goto end;
        }
        if (b != NULL) {
            if (!BUF_MEM_grow(b, l + 1))
                goto err;
            p = &(b->data[lold]);
        } else if (l > len) {
            break;
        } else
            p = &(buf[lold]);
        *(p++) = '/';
        memcpy(p, s, (unsigned int)l1);
        p += l1;
        *(p++) = '=';
#ifndef CHARSET_EBCDIC
        q = ne->value->data;
#endif
        for (j = 0; j < num; j++) {
            if (!gs_doit[j & 3])
                continue;
#ifndef CHARSET_EBCDIC
            n = q[j];
            if ((n < ' ') || (n > '~')) {
                *(p++) = '\\';
                *(p++) = 'x';
                *(p++) = hex[(n >> 4) & 0x0f];
                *(p++) = hex[n & 0x0f];
            } else
                *(p++) = n;
#else
            n = os_toascii[q[j]];
            if ((n < os_toascii[' ']) || (n > os_toascii['~'])) {
                *(p++) = '\\';
                *(p++) = 'x';
                *(p++) = hex[(n >> 4) & 0x0f];
                *(p++) = hex[n & 0x0f];
            } else
                *(p++) = q[j];
#endif
        }
        *p = '\0';
    }
    if (b != NULL) {
        p = b->data;
        OPENSSL_free(b);
    } else
        p = buf;
    if (i == 0)
        *p = '\0';
    return (p);
 err:
    X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
 end:
    BUF_MEM_free(b);
    return (NULL);
}
['int x509_main(int argc, char **argv)\n{\n    ASN1_INTEGER *sno = NULL;\n    ASN1_OBJECT *objtmp = NULL;\n    BIO *out = NULL;\n    CONF *extconf = NULL;\n    EVP_PKEY *Upkey = NULL, *CApkey = NULL, *fkey = NULL;\n    STACK_OF(ASN1_OBJECT) *trust = NULL, *reject = NULL;\n    STACK_OF(OPENSSL_STRING) *sigopts = NULL;\n    X509 *x = NULL, *xca = NULL;\n    X509_REQ *req = NULL, *rq = NULL;\n    X509_STORE *ctx = NULL;\n    const EVP_MD *digest = NULL;\n    char *CAkeyfile = NULL, *CAserial = NULL, *fkeyfile = NULL, *alias = NULL;\n    char *checkhost = NULL, *checkemail = NULL, *checkip = NULL;\n    char *extsect = NULL, *extfile = NULL, *passin = NULL, *passinarg = NULL;\n    char *infile = NULL, *outfile = NULL, *keyfile = NULL, *CAfile = NULL;\n    char buf[256], *prog;\n    int x509req = 0, days = DEF_DAYS, modulus = 0, pubkey = 0, pprint = 0;\n    int C = 0, CAformat = FORMAT_PEM, CAkeyformat = FORMAT_PEM;\n    int fingerprint = 0, reqfile = 0, need_rand = 0, checkend = 0;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM, keyformat = FORMAT_PEM;\n    int next_serial = 0, subject_hash = 0, issuer_hash = 0, ocspid = 0;\n    int noout = 0, sign_flag = 0, CA_flag = 0, CA_createserial = 0, email = 0;\n    int ocsp_uri = 0, trustout = 0, clrtrust = 0, clrreject = 0, aliasout = 0;\n    int ret = 1, i, num = 0, badsig = 0, clrext = 0, nocert = 0;\n    int text = 0, serial = 0, subject = 0, issuer = 0, startdate = 0;\n    int enddate = 0;\n    time_t checkoffset = 0;\n    unsigned long nmflag = 0, certflag = 0;\n    char nmflag_set = 0;\n    OPTION_CHOICE o;\n    ENGINE *e = NULL;\n#ifndef OPENSSL_NO_MD5\n    int subject_hash_old = 0, issuer_hash_old = 0;\n#endif\n    ctx = X509_STORE_new();\n    if (ctx == NULL)\n        goto end;\n    X509_STORE_set_verify_cb(ctx, callb);\n    prog = opt_init(argc, argv, x509_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(x509_options);\n            ret = 0;\n            goto end;\n        case OPT_INFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &informat))\n                goto opthelp;\n            break;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &outformat))\n                goto opthelp;\n            break;\n        case OPT_KEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &keyformat))\n                goto opthelp;\n            break;\n        case OPT_CAFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &CAformat))\n                goto opthelp;\n            break;\n        case OPT_CAKEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &CAkeyformat))\n                goto opthelp;\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_REQ:\n            reqfile = need_rand = 1;\n            break;\n        case OPT_SIGOPT:\n            if (!sigopts)\n                sigopts = sk_OPENSSL_STRING_new_null();\n            if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_DAYS:\n            days = atoi(opt_arg());\n            break;\n        case OPT_PASSIN:\n            passinarg = opt_arg();\n            break;\n        case OPT_EXTFILE:\n            extfile = opt_arg();\n            break;\n        case OPT_EXTENSIONS:\n            extsect = opt_arg();\n            break;\n        case OPT_SIGNKEY:\n            keyfile = opt_arg();\n            sign_flag = ++num;\n            need_rand = 1;\n            break;\n        case OPT_CA:\n            CAfile = opt_arg();\n            CA_flag = ++num;\n            need_rand = 1;\n            break;\n        case OPT_CAKEY:\n            CAkeyfile = opt_arg();\n            break;\n        case OPT_CASERIAL:\n            CAserial = opt_arg();\n            break;\n        case OPT_SET_SERIAL:\n            if (sno != NULL) {\n                BIO_printf(bio_err, "Serial number supplied twice\\n");\n                goto opthelp;\n            }\n            if ((sno = s2i_ASN1_INTEGER(NULL, opt_arg())) == NULL)\n                goto opthelp;\n            break;\n        case OPT_FORCE_PUBKEY:\n            fkeyfile = opt_arg();\n            break;\n        case OPT_ADDTRUST:\n            if ((objtmp = OBJ_txt2obj(opt_arg(), 0)) == NULL) {\n                BIO_printf(bio_err,\n                           "%s: Invalid trust object value %s\\n",\n                           prog, opt_arg());\n                goto opthelp;\n            }\n            if (trust == NULL && (trust = sk_ASN1_OBJECT_new_null()) == NULL)\n                goto end;\n            sk_ASN1_OBJECT_push(trust, objtmp);\n            objtmp = NULL;\n            trustout = 1;\n            break;\n        case OPT_ADDREJECT:\n            if ((objtmp = OBJ_txt2obj(opt_arg(), 0)) == NULL) {\n                BIO_printf(bio_err,\n                           "%s: Invalid reject object value %s\\n",\n                           prog, opt_arg());\n                goto opthelp;\n            }\n            if (reject == NULL\n                && (reject = sk_ASN1_OBJECT_new_null()) == NULL)\n                goto end;\n            sk_ASN1_OBJECT_push(reject, objtmp);\n            objtmp = NULL;\n            trustout = 1;\n            break;\n        case OPT_SETALIAS:\n            alias = opt_arg();\n            trustout = 1;\n            break;\n        case OPT_CERTOPT:\n            if (!set_cert_ex(&certflag, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_NAMEOPT:\n            nmflag_set = 1;\n            if (!set_name_ex(&nmflag, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_ENGINE:\n            e = setup_engine(opt_arg(), 0);\n            break;\n        case OPT_C:\n            C = ++num;\n            break;\n        case OPT_EMAIL:\n            email = ++num;\n            break;\n        case OPT_OCSP_URI:\n            ocsp_uri = ++num;\n            break;\n        case OPT_SERIAL:\n            serial = ++num;\n            break;\n        case OPT_NEXT_SERIAL:\n            next_serial = ++num;\n            break;\n        case OPT_MODULUS:\n            modulus = ++num;\n            break;\n        case OPT_PUBKEY:\n            pubkey = ++num;\n            break;\n        case OPT_X509TOREQ:\n            x509req = ++num;\n            break;\n        case OPT_TEXT:\n            text = ++num;\n            break;\n        case OPT_SUBJECT:\n            subject = ++num;\n            break;\n        case OPT_ISSUER:\n            issuer = ++num;\n            break;\n        case OPT_FINGERPRINT:\n            fingerprint = ++num;\n            break;\n        case OPT_HASH:\n            subject_hash = ++num;\n            break;\n        case OPT_ISSUER_HASH:\n            issuer_hash = ++num;\n            break;\n        case OPT_PURPOSE:\n            pprint = ++num;\n            break;\n        case OPT_STARTDATE:\n            startdate = ++num;\n            break;\n        case OPT_ENDDATE:\n            enddate = ++num;\n            break;\n        case OPT_NOOUT:\n            noout = ++num;\n            break;\n        case OPT_NOCERT:\n            nocert = 1;\n            break;\n        case OPT_TRUSTOUT:\n            trustout = 1;\n            break;\n        case OPT_CLRTRUST:\n            clrtrust = ++num;\n            break;\n        case OPT_CLRREJECT:\n            clrreject = ++num;\n            break;\n        case OPT_ALIAS:\n            aliasout = ++num;\n            break;\n        case OPT_CACREATESERIAL:\n            CA_createserial = ++num;\n            break;\n        case OPT_CLREXT:\n            clrext = 1;\n            break;\n        case OPT_OCSPID:\n            ocspid = ++num;\n            break;\n        case OPT_BADSIG:\n            badsig = 1;\n            break;\n#ifndef OPENSSL_NO_MD5\n        case OPT_SUBJECT_HASH_OLD:\n            subject_hash_old = ++num;\n            break;\n        case OPT_ISSUER_HASH_OLD:\n            issuer_hash_old = ++num;\n            break;\n#else\n        case OPT_SUBJECT_HASH_OLD:\n        case OPT_ISSUER_HASH_OLD:\n            break;\n#endif\n        case OPT_DATES:\n            startdate = ++num;\n            enddate = ++num;\n            break;\n        case OPT_CHECKEND:\n            checkend = 1;\n            {\n                intmax_t temp = 0;\n                if (!opt_imax(opt_arg(), &temp))\n                    goto opthelp;\n                checkoffset = (time_t)temp;\n                if ((intmax_t)checkoffset != temp) {\n                    BIO_printf(bio_err, "%s: checkend time out of range %s\\n",\n                               prog, opt_arg());\n                    goto opthelp;\n                }\n            }\n            break;\n        case OPT_CHECKHOST:\n            checkhost = opt_arg();\n            break;\n        case OPT_CHECKEMAIL:\n            checkemail = opt_arg();\n            break;\n        case OPT_CHECKIP:\n            checkip = opt_arg();\n            break;\n        case OPT_MD:\n            if (!opt_md(opt_unknown(), &digest))\n                goto opthelp;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (argc != 0) {\n        BIO_printf(bio_err, "%s: Unknown parameter %s\\n", prog, argv[0]);\n        goto opthelp;\n    }\n    if (!nmflag_set)\n        nmflag = XN_FLAG_ONELINE;\n    out = bio_open_default(outfile, \'w\', outformat);\n    if (out == NULL)\n        goto end;\n    if (need_rand)\n        app_RAND_load_file(NULL, 0);\n    if (!app_passwd(passinarg, NULL, &passin, NULL)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    if (!X509_STORE_set_default_paths(ctx)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (fkeyfile) {\n        fkey = load_pubkey(fkeyfile, keyformat, 0, NULL, e, "Forced key");\n        if (fkey == NULL)\n            goto end;\n    }\n    if ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM)) {\n        CAkeyfile = CAfile;\n    } else if ((CA_flag) && (CAkeyfile == NULL)) {\n        BIO_printf(bio_err,\n                   "need to specify a CAkey if using the CA command\\n");\n        goto end;\n    }\n    if (extfile) {\n        X509V3_CTX ctx2;\n        if ((extconf = app_load_config(extfile)) == NULL)\n            goto end;\n        if (!extsect) {\n            extsect = NCONF_get_string(extconf, "default", "extensions");\n            if (!extsect) {\n                ERR_clear_error();\n                extsect = "default";\n            }\n        }\n        X509V3_set_ctx_test(&ctx2);\n        X509V3_set_nconf(&ctx2, extconf);\n        if (!X509V3_EXT_add_nconf(extconf, &ctx2, extsect, NULL)) {\n            BIO_printf(bio_err,\n                       "Error Loading extension section %s\\n", extsect);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (reqfile) {\n        EVP_PKEY *pkey;\n        BIO *in;\n        if (!sign_flag && !CA_flag) {\n            BIO_printf(bio_err, "We need a private key to sign with\\n");\n            goto end;\n        }\n        in = bio_open_default(infile, \'r\', informat);\n        if (in == NULL)\n            goto end;\n        req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);\n        BIO_free(in);\n        if (req == NULL) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if ((pkey = X509_REQ_get0_pubkey(req)) == NULL) {\n            BIO_printf(bio_err, "error unpacking public key\\n");\n            goto end;\n        }\n        i = X509_REQ_verify(req, pkey);\n        if (i < 0) {\n            BIO_printf(bio_err, "Signature verification error\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (i == 0) {\n            BIO_printf(bio_err,\n                       "Signature did not match the certificate request\\n");\n            goto end;\n        } else\n            BIO_printf(bio_err, "Signature ok\\n");\n        print_name(bio_err, "subject=", X509_REQ_get_subject_name(req),\n                   nmflag);\n        if ((x = X509_new()) == NULL)\n            goto end;\n        if (sno == NULL) {\n            sno = ASN1_INTEGER_new();\n            if (sno == NULL || !rand_serial(NULL, sno))\n                goto end;\n            if (!X509_set_serialNumber(x, sno))\n                goto end;\n            ASN1_INTEGER_free(sno);\n            sno = NULL;\n        } else if (!X509_set_serialNumber(x, sno))\n            goto end;\n        if (!X509_set_issuer_name(x, X509_REQ_get_subject_name(req)))\n            goto end;\n        if (!X509_set_subject_name(x, X509_REQ_get_subject_name(req)))\n            goto end;\n        if (!set_cert_times(x, NULL, NULL, days))\n            goto end;\n        if (fkey)\n            X509_set_pubkey(x, fkey);\n        else {\n            pkey = X509_REQ_get0_pubkey(req);\n            X509_set_pubkey(x, pkey);\n        }\n    } else\n        x = load_cert(infile, informat, "Certificate");\n    if (x == NULL)\n        goto end;\n    if (CA_flag) {\n        xca = load_cert(CAfile, CAformat, "CA Certificate");\n        if (xca == NULL)\n            goto end;\n    }\n    if (!noout || text || next_serial) {\n        OBJ_create("2.99999.3", "SET.ex3", "SET x509v3 extension 3");\n    }\n    if (alias)\n        X509_alias_set1(x, (unsigned char *)alias, -1);\n    if (clrtrust)\n        X509_trust_clear(x);\n    if (clrreject)\n        X509_reject_clear(x);\n    if (trust) {\n        for (i = 0; i < sk_ASN1_OBJECT_num(trust); i++) {\n            objtmp = sk_ASN1_OBJECT_value(trust, i);\n            X509_add1_trust_object(x, objtmp);\n        }\n        objtmp = NULL;\n    }\n    if (reject) {\n        for (i = 0; i < sk_ASN1_OBJECT_num(reject); i++) {\n            objtmp = sk_ASN1_OBJECT_value(reject, i);\n            X509_add1_reject_object(x, objtmp);\n        }\n        objtmp = NULL;\n    }\n    if (badsig) {\n        const ASN1_BIT_STRING *signature;\n        X509_get0_signature(&signature, NULL, x);\n        corrupt_signature(signature);\n    }\n    if (num) {\n        for (i = 1; i <= num; i++) {\n            if (issuer == i) {\n                print_name(out, "issuer=", X509_get_issuer_name(x), nmflag);\n            } else if (subject == i) {\n                print_name(out, "subject=",\n                           X509_get_subject_name(x), nmflag);\n            } else if (serial == i) {\n                BIO_printf(out, "serial=");\n                i2a_ASN1_INTEGER(out, X509_get_serialNumber(x));\n                BIO_printf(out, "\\n");\n            } else if (next_serial == i) {\n                ASN1_INTEGER *ser = X509_get_serialNumber(x);\n                BIGNUM *bnser = ASN1_INTEGER_to_BN(ser, NULL);\n                if (!bnser)\n                    goto end;\n                if (!BN_add_word(bnser, 1))\n                    goto end;\n                ser = BN_to_ASN1_INTEGER(bnser, NULL);\n                if (!ser)\n                    goto end;\n                BN_free(bnser);\n                i2a_ASN1_INTEGER(out, ser);\n                ASN1_INTEGER_free(ser);\n                BIO_puts(out, "\\n");\n            } else if ((email == i) || (ocsp_uri == i)) {\n                int j;\n                STACK_OF(OPENSSL_STRING) *emlst;\n                if (email == i)\n                    emlst = X509_get1_email(x);\n                else\n                    emlst = X509_get1_ocsp(x);\n                for (j = 0; j < sk_OPENSSL_STRING_num(emlst); j++)\n                    BIO_printf(out, "%s\\n",\n                               sk_OPENSSL_STRING_value(emlst, j));\n                X509_email_free(emlst);\n            } else if (aliasout == i) {\n                unsigned char *alstr;\n                alstr = X509_alias_get0(x, NULL);\n                if (alstr)\n                    BIO_printf(out, "%s\\n", alstr);\n                else\n                    BIO_puts(out, "<No Alias>\\n");\n            } else if (subject_hash == i) {\n                BIO_printf(out, "%08lx\\n", X509_subject_name_hash(x));\n            }\n#ifndef OPENSSL_NO_MD5\n            else if (subject_hash_old == i) {\n                BIO_printf(out, "%08lx\\n", X509_subject_name_hash_old(x));\n            }\n#endif\n            else if (issuer_hash == i) {\n                BIO_printf(out, "%08lx\\n", X509_issuer_name_hash(x));\n            }\n#ifndef OPENSSL_NO_MD5\n            else if (issuer_hash_old == i) {\n                BIO_printf(out, "%08lx\\n", X509_issuer_name_hash_old(x));\n            }\n#endif\n            else if (pprint == i) {\n                X509_PURPOSE *ptmp;\n                int j;\n                BIO_printf(out, "Certificate purposes:\\n");\n                for (j = 0; j < X509_PURPOSE_get_count(); j++) {\n                    ptmp = X509_PURPOSE_get0(j);\n                    purpose_print(out, x, ptmp);\n                }\n            } else if (modulus == i) {\n                EVP_PKEY *pkey;\n                pkey = X509_get0_pubkey(x);\n                if (pkey == NULL) {\n                    BIO_printf(bio_err, "Modulus=unavailable\\n");\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n                BIO_printf(out, "Modulus=");\n#ifndef OPENSSL_NO_RSA\n                if (EVP_PKEY_id(pkey) == EVP_PKEY_RSA) {\n                    const BIGNUM *n;\n                    RSA_get0_key(EVP_PKEY_get0_RSA(pkey), &n, NULL, NULL);\n                    BN_print(out, n);\n                } else\n#endif\n#ifndef OPENSSL_NO_DSA\n                if (EVP_PKEY_id(pkey) == EVP_PKEY_DSA) {\n                    const BIGNUM *dsapub = NULL;\n                    DSA_get0_key(EVP_PKEY_get0_DSA(pkey), &dsapub, NULL);\n                    BN_print(out, dsapub);\n                } else\n#endif\n                {\n                    BIO_printf(out, "Wrong Algorithm type");\n                }\n                BIO_printf(out, "\\n");\n            } else if (pubkey == i) {\n                EVP_PKEY *pkey;\n                pkey = X509_get0_pubkey(x);\n                if (pkey == NULL) {\n                    BIO_printf(bio_err, "Error getting public key\\n");\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n                PEM_write_bio_PUBKEY(out, pkey);\n            } else if (C == i) {\n                unsigned char *d;\n                char *m;\n                int len;\n                X509_NAME_oneline(X509_get_subject_name(x), buf, sizeof buf);\n                BIO_printf(out, "/*\\n"\n                                " * Subject: %s\\n", buf);\n                X509_NAME_oneline(X509_get_issuer_name(x), buf, sizeof buf);\n                BIO_printf(out, " * Issuer:  %s\\n"\n                                " */\\n", buf);\n                len = i2d_X509(x, NULL);\n                m = app_malloc(len, "x509 name buffer");\n                d = (unsigned char *)m;\n                len = i2d_X509_NAME(X509_get_subject_name(x), &d);\n                print_array(out, "the_subject_name", len, (unsigned char *)m);\n                d = (unsigned char *)m;\n                len = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &d);\n                print_array(out, "the_public_key", len, (unsigned char *)m);\n                d = (unsigned char *)m;\n                len = i2d_X509(x, &d);\n                print_array(out, "the_certificate", len, (unsigned char *)m);\n                OPENSSL_free(m);\n            } else if (text == i) {\n                X509_print_ex(out, x, nmflag, certflag);\n            } else if (startdate == i) {\n                BIO_puts(out, "notBefore=");\n                ASN1_TIME_print(out, X509_get0_notBefore(x));\n                BIO_puts(out, "\\n");\n            } else if (enddate == i) {\n                BIO_puts(out, "notAfter=");\n                ASN1_TIME_print(out, X509_get0_notAfter(x));\n                BIO_puts(out, "\\n");\n            } else if (fingerprint == i) {\n                int j;\n                unsigned int n;\n                unsigned char md[EVP_MAX_MD_SIZE];\n                const EVP_MD *fdig = digest;\n                if (!fdig)\n                    fdig = EVP_sha1();\n                if (!X509_digest(x, fdig, md, &n)) {\n                    BIO_printf(bio_err, "out of memory\\n");\n                    goto end;\n                }\n                BIO_printf(out, "%s Fingerprint=",\n                           OBJ_nid2sn(EVP_MD_type(fdig)));\n                for (j = 0; j < (int)n; j++) {\n                    BIO_printf(out, "%02X%c", md[j], (j + 1 == (int)n)\n                               ? \'\\n\' : \':\');\n                }\n            }\n            else if ((sign_flag == i) && (x509req == 0)) {\n                BIO_printf(bio_err, "Getting Private key\\n");\n                if (Upkey == NULL) {\n                    Upkey = load_key(keyfile, keyformat, 0,\n                                     passin, e, "Private key");\n                    if (Upkey == NULL)\n                        goto end;\n                }\n                assert(need_rand);\n                if (!sign(x, Upkey, days, clrext, digest, extconf, extsect))\n                    goto end;\n            } else if (CA_flag == i) {\n                BIO_printf(bio_err, "Getting CA Private Key\\n");\n                if (CAkeyfile != NULL) {\n                    CApkey = load_key(CAkeyfile, CAkeyformat,\n                                      0, passin, e, "CA Private Key");\n                    if (CApkey == NULL)\n                        goto end;\n                }\n                assert(need_rand);\n                if (!x509_certify(ctx, CAfile, digest, x, xca,\n                                  CApkey, sigopts,\n                                  CAserial, CA_createserial, days, clrext,\n                                  extconf, extsect, sno, reqfile))\n                    goto end;\n            } else if (x509req == i) {\n                EVP_PKEY *pk;\n                BIO_printf(bio_err, "Getting request Private Key\\n");\n                if (keyfile == NULL) {\n                    BIO_printf(bio_err, "no request key file specified\\n");\n                    goto end;\n                } else {\n                    pk = load_key(keyfile, keyformat, 0,\n                                  passin, e, "request key");\n                    if (pk == NULL)\n                        goto end;\n                }\n                BIO_printf(bio_err, "Generating certificate request\\n");\n                rq = X509_to_X509_REQ(x, pk, digest);\n                EVP_PKEY_free(pk);\n                if (rq == NULL) {\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n                if (!noout) {\n                    X509_REQ_print(out, rq);\n                    PEM_write_bio_X509_REQ(out, rq);\n                }\n                noout = 1;\n            } else if (ocspid == i) {\n                X509_ocspid_print(out, x);\n            }\n        }\n    }\n    if (checkend) {\n        time_t tcheck = time(NULL) + checkoffset;\n        if (X509_cmp_time(X509_get0_notAfter(x), &tcheck) < 0) {\n            BIO_printf(out, "Certificate will expire\\n");\n            ret = 1;\n        } else {\n            BIO_printf(out, "Certificate will not expire\\n");\n            ret = 0;\n        }\n        goto end;\n    }\n    print_cert_checks(out, x, checkhost, checkemail, checkip);\n    if (noout || nocert) {\n        ret = 0;\n        goto end;\n    }\n    if (outformat == FORMAT_ASN1)\n        i = i2d_X509_bio(out, x);\n    else if (outformat == FORMAT_PEM) {\n        if (trustout)\n            i = PEM_write_bio_X509_AUX(out, x);\n        else\n            i = PEM_write_bio_X509(out, x);\n    } else {\n        BIO_printf(bio_err, "bad output format specified for outfile\\n");\n        goto end;\n    }\n    if (!i) {\n        BIO_printf(bio_err, "unable to write certificate\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    ret = 0;\n end:\n    if (need_rand)\n        app_RAND_write_file(NULL);\n    NCONF_free(extconf);\n    BIO_free_all(out);\n    X509_STORE_free(ctx);\n    X509_REQ_free(req);\n    X509_free(x);\n    X509_free(xca);\n    EVP_PKEY_free(Upkey);\n    EVP_PKEY_free(CApkey);\n    EVP_PKEY_free(fkey);\n    sk_OPENSSL_STRING_free(sigopts);\n    X509_REQ_free(rq);\n    ASN1_INTEGER_free(sno);\n    sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);\n    sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);\n    ASN1_OBJECT_free(objtmp);\n    release_engine(e);\n    OPENSSL_free(passin);\n    return (ret);\n}', 'char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)\n{\n    const X509_NAME_ENTRY *ne;\n    int i;\n    int n, lold, l, l1, l2, num, j, type;\n    const char *s;\n    char *p;\n    unsigned char *q;\n    BUF_MEM *b = NULL;\n    static const char hex[17] = "0123456789ABCDEF";\n    int gs_doit[4];\n    char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n    unsigned char ebcdic_buf[1024];\n#endif\n    if (buf == NULL) {\n        if ((b = BUF_MEM_new()) == NULL)\n            goto err;\n        if (!BUF_MEM_grow(b, 200))\n            goto err;\n        b->data[0] = \'\\0\';\n        len = 200;\n    } else if (len == 0) {\n        return NULL;\n    }\n    if (a == NULL) {\n        if (b) {\n            buf = b->data;\n            OPENSSL_free(b);\n        }\n        strncpy(buf, "NO X509_NAME", len);\n        buf[len - 1] = \'\\0\';\n        return buf;\n    }\n    len--;\n    l = 0;\n    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n        ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n        n = OBJ_obj2nid(ne->object);\n        if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n            i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n            s = tmp_buf;\n        }\n        l1 = strlen(s);\n        type = ne->value->type;\n        num = ne->value->length;\n        if (num > NAME_ONELINE_MAX) {\n            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n            goto end;\n        }\n        q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n        if (type == V_ASN1_GENERALSTRING ||\n            type == V_ASN1_VISIBLESTRING ||\n            type == V_ASN1_PRINTABLESTRING ||\n            type == V_ASN1_TELETEXSTRING ||\n            type == V_ASN1_IA5STRING) {\n            if (num > (int)sizeof(ebcdic_buf))\n                num = sizeof(ebcdic_buf);\n            ascii2ebcdic(ebcdic_buf, q, num);\n            q = ebcdic_buf;\n        }\n#endif\n        if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n            for (j = 0; j < num; j++)\n                if (q[j] != 0)\n                    gs_doit[j & 3] = 1;\n            if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n                gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n            else {\n                gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n                gs_doit[3] = 1;\n            }\n        } else\n            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n        for (l2 = j = 0; j < num; j++) {\n            if (!gs_doit[j & 3])\n                continue;\n            l2++;\n#ifndef CHARSET_EBCDIC\n            if ((q[j] < \' \') || (q[j] > \'~\'))\n                l2 += 3;\n#else\n            if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n                (os_toascii[q[j]] > os_toascii[\'~\']))\n                l2 += 3;\n#endif\n        }\n        lold = l;\n        l += 1 + l1 + 1 + l2;\n        if (l > NAME_ONELINE_MAX) {\n            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n            goto end;\n        }\n        if (b != NULL) {\n            if (!BUF_MEM_grow(b, l + 1))\n                goto err;\n            p = &(b->data[lold]);\n        } else if (l > len) {\n            break;\n        } else\n            p = &(buf[lold]);\n        *(p++) = \'/\';\n        memcpy(p, s, (unsigned int)l1);\n        p += l1;\n        *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n        q = ne->value->data;\n#endif\n        for (j = 0; j < num; j++) {\n            if (!gs_doit[j & 3])\n                continue;\n#ifndef CHARSET_EBCDIC\n            n = q[j];\n            if ((n < \' \') || (n > \'~\')) {\n                *(p++) = \'\\\\\';\n                *(p++) = \'x\';\n                *(p++) = hex[(n >> 4) & 0x0f];\n                *(p++) = hex[n & 0x0f];\n            } else\n                *(p++) = n;\n#else\n            n = os_toascii[q[j]];\n            if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n                *(p++) = \'\\\\\';\n                *(p++) = \'x\';\n                *(p++) = hex[(n >> 4) & 0x0f];\n                *(p++) = hex[n & 0x0f];\n            } else\n                *(p++) = q[j];\n#endif\n        }\n        *p = \'\\0\';\n    }\n    if (b != NULL) {\n        p = b->data;\n        OPENSSL_free(b);\n    } else\n        p = buf;\n    if (i == 0)\n        *p = \'\\0\';\n    return (p);\n err:\n    X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n end:\n    BUF_MEM_free(b);\n    return (NULL);\n}']