apps/pkeyutl.c:332: error: UNINITIALIZED_VALUE
  The value read from buf_outlen was never initialized.
Showing all 1 steps of the trace


apps/pkeyutl.c:332:9: 
330.           BIO_dump(out, (char *)buf_out, buf_outlen);
331.       else
332. >         BIO_write(out, buf_out, buf_outlen);
333.   
334.    end:

int MAIN(int argc, char **argv)
{
    BIO *in = NULL, *out = NULL;
    char *infile = NULL, *outfile = NULL, *sigfile = NULL;
    ENGINE *e = NULL;
    int pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;
    int keyform = FORMAT_PEM, peerform = FORMAT_PEM;
    char badarg = 0, rev = 0;
    char hexdump = 0, asn1parse = 0;
    EVP_PKEY_CTX *ctx = NULL;
    char *passargin = NULL;
    int keysize = -1;
    unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
    size_t buf_outlen;
    int buf_inlen = 0, siglen = -1;
    int ret = 1, rv = -1;
    argc--;
    argv++;
    if (!bio_err)
        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
    if (!load_config(bio_err, NULL))
        goto end;
    ERR_load_crypto_strings();
    OpenSSL_add_all_algorithms();
    while (argc >= 1) {
        if (!strcmp(*argv, "-in")) {
            if (--argc < 1)
                badarg = 1;
            else
                infile = *(++argv);
        } else if (!strcmp(*argv, "-out")) {
            if (--argc < 1)
                badarg = 1;
            else
                outfile = *(++argv);
        } else if (!strcmp(*argv, "-sigfile")) {
            if (--argc < 1)
                badarg = 1;
            else
                sigfile = *(++argv);
        } else if (!strcmp(*argv, "-inkey")) {
            if (--argc < 1)
                badarg = 1;
            else {
                ctx = init_ctx(&keysize,
                               *(++argv), keyform, key_type,
                               passargin, pkey_op, e);
                if (!ctx) {
                    BIO_puts(bio_err, "Error initializing context\n");
                    ERR_print_errors(bio_err);
                    badarg = 1;
                }
            }
        } else if (!strcmp(*argv, "-peerkey")) {
            if (--argc < 1)
                badarg = 1;
            else if (!setup_peer(bio_err, ctx, peerform, *(++argv)))
                badarg = 1;
        } else if (!strcmp(*argv, "-passin")) {
            if (--argc < 1)
                badarg = 1;
            else
                passargin = *(++argv);
        } else if (strcmp(*argv, "-peerform") == 0) {
            if (--argc < 1)
                badarg = 1;
            else
                peerform = str2fmt(*(++argv));
        } else if (strcmp(*argv, "-keyform") == 0) {
            if (--argc < 1)
                badarg = 1;
            else
                keyform = str2fmt(*(++argv));
        }
#ifndef OPENSSL_NO_ENGINE
        else if (!strcmp(*argv, "-engine")) {
            if (--argc < 1)
                badarg = 1;
            else
                e = setup_engine(bio_err, *(++argv), 0);
        }
#endif
        else if (!strcmp(*argv, "-pubin"))
            key_type = KEY_PUBKEY;
        else if (!strcmp(*argv, "-certin"))
            key_type = KEY_CERT;
        else if (!strcmp(*argv, "-asn1parse"))
            asn1parse = 1;
        else if (!strcmp(*argv, "-hexdump"))
            hexdump = 1;
        else if (!strcmp(*argv, "-sign"))
            pkey_op = EVP_PKEY_OP_SIGN;
        else if (!strcmp(*argv, "-verify"))
            pkey_op = EVP_PKEY_OP_VERIFY;
        else if (!strcmp(*argv, "-verifyrecover"))
            pkey_op = EVP_PKEY_OP_VERIFYRECOVER;
        else if (!strcmp(*argv, "-rev"))
            rev = 1;
        else if (!strcmp(*argv, "-encrypt"))
            pkey_op = EVP_PKEY_OP_ENCRYPT;
        else if (!strcmp(*argv, "-decrypt"))
            pkey_op = EVP_PKEY_OP_DECRYPT;
        else if (!strcmp(*argv, "-derive"))
            pkey_op = EVP_PKEY_OP_DERIVE;
        else if (strcmp(*argv, "-pkeyopt") == 0) {
            if (--argc < 1)
                badarg = 1;
            else if (!ctx) {
                BIO_puts(bio_err, "-pkeyopt command before -inkey\n");
                badarg = 1;
            } else if (pkey_ctrl_string(ctx, *(++argv)) <= 0) {
                BIO_puts(bio_err, "parameter setting error\n");
                ERR_print_errors(bio_err);
                goto end;
            }
        } else
            badarg = 1;
        if (badarg) {
            usage();
            goto end;
        }
        argc--;
        argv++;
    }
    if (!ctx) {
        usage();
        goto end;
    }
    if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY)) {
        BIO_puts(bio_err, "Signature file specified for non verify\n");
        goto end;
    }
    if (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY)) {
        BIO_puts(bio_err, "No signature file specified for verify\n");
        goto end;
    }
    app_RAND_load_file(NULL, bio_err, 0);
    if (pkey_op != EVP_PKEY_OP_DERIVE) {
        if (infile) {
            if (!(in = BIO_new_file(infile, "rb"))) {
                BIO_puts(bio_err, "Error Opening Input File\n");
                ERR_print_errors(bio_err);
                goto end;
            }
        } else
            in = BIO_new_fp(stdin, BIO_NOCLOSE);
    }
    if (outfile) {
        if (!(out = BIO_new_file(outfile, "wb"))) {
            BIO_printf(bio_err, "Error Creating Output File\n");
            ERR_print_errors(bio_err);
            goto end;
        }
    } else {
        out = BIO_new_fp(stdout, BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
        {
            BIO *tmpbio = BIO_new(BIO_f_linebuffer());
            out = BIO_push(tmpbio, out);
        }
#endif
    }
    if (sigfile) {
        BIO *sigbio = BIO_new_file(sigfile, "rb");
        if (!sigbio) {
            BIO_printf(bio_err, "Can't open signature file %s\n", sigfile);
            goto end;
        }
        siglen = bio_to_mem(&sig, keysize * 10, sigbio);
        BIO_free(sigbio);
        if (siglen <= 0) {
            BIO_printf(bio_err, "Error reading signature data\n");
            goto end;
        }
    }
    if (in) {
        buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
        if (buf_inlen <= 0) {
            BIO_printf(bio_err, "Error reading input Data\n");
            exit(1);
        }
        if (rev) {
            size_t i;
            unsigned char ctmp;
            size_t l = (size_t)buf_inlen;
            for (i = 0; i < l / 2; i++) {
                ctmp = buf_in[i];
                buf_in[i] = buf_in[l - 1 - i];
                buf_in[l - 1 - i] = ctmp;
            }
        }
    }
    if (pkey_op == EVP_PKEY_OP_VERIFY) {
        rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
                             buf_in, (size_t)buf_inlen);
        if (rv == 0)
            BIO_puts(out, "Signature Verification Failure\n");
        else if (rv == 1)
            BIO_puts(out, "Signature Verified Successfully\n");
        if (rv >= 0)
            goto end;
    } else {
        rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
                      buf_in, (size_t)buf_inlen);
        if (rv > 0) {
            buf_out = OPENSSL_malloc(buf_outlen);
            if (!buf_out)
                rv = -1;
            else
                rv = do_keyop(ctx, pkey_op,
                              buf_out, (size_t *)&buf_outlen,
                              buf_in, (size_t)buf_inlen);
        }
    }
    if (rv <= 0) {
        BIO_printf(bio_err, "Public Key operation error\n");
        ERR_print_errors(bio_err);
        goto end;
    }
    ret = 0;
    if (asn1parse) {
        if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))
            ERR_print_errors(bio_err);
    } else if (hexdump)
        BIO_dump(out, (char *)buf_out, buf_outlen);
    else
        BIO_write(out, buf_out, buf_outlen);
 end:
    if (ctx)
        EVP_PKEY_CTX_free(ctx);
    BIO_free(in);
    BIO_free_all(out);
    if (buf_in)
        OPENSSL_free(buf_in);
    if (buf_out)
        OPENSSL_free(buf_out);
    if (sig)
        OPENSSL_free(sig);
    return ret;
}
['int MAIN(int argc, char **argv)\n{\n    BIO *in = NULL, *out = NULL;\n    char *infile = NULL, *outfile = NULL, *sigfile = NULL;\n    ENGINE *e = NULL;\n    int pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;\n    int keyform = FORMAT_PEM, peerform = FORMAT_PEM;\n    char badarg = 0, rev = 0;\n    char hexdump = 0, asn1parse = 0;\n    EVP_PKEY_CTX *ctx = NULL;\n    char *passargin = NULL;\n    int keysize = -1;\n    unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;\n    size_t buf_outlen;\n    int buf_inlen = 0, siglen = -1;\n    int ret = 1, rv = -1;\n    argc--;\n    argv++;\n    if (!bio_err)\n        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);\n    if (!load_config(bio_err, NULL))\n        goto end;\n    ERR_load_crypto_strings();\n    OpenSSL_add_all_algorithms();\n    while (argc >= 1) {\n        if (!strcmp(*argv, "-in")) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                infile = *(++argv);\n        } else if (!strcmp(*argv, "-out")) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                outfile = *(++argv);\n        } else if (!strcmp(*argv, "-sigfile")) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                sigfile = *(++argv);\n        } else if (!strcmp(*argv, "-inkey")) {\n            if (--argc < 1)\n                badarg = 1;\n            else {\n                ctx = init_ctx(&keysize,\n                               *(++argv), keyform, key_type,\n                               passargin, pkey_op, e);\n                if (!ctx) {\n                    BIO_puts(bio_err, "Error initializing context\\n");\n                    ERR_print_errors(bio_err);\n                    badarg = 1;\n                }\n            }\n        } else if (!strcmp(*argv, "-peerkey")) {\n            if (--argc < 1)\n                badarg = 1;\n            else if (!setup_peer(bio_err, ctx, peerform, *(++argv)))\n                badarg = 1;\n        } else if (!strcmp(*argv, "-passin")) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                passargin = *(++argv);\n        } else if (strcmp(*argv, "-peerform") == 0) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                peerform = str2fmt(*(++argv));\n        } else if (strcmp(*argv, "-keyform") == 0) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                keyform = str2fmt(*(++argv));\n        }\n#ifndef OPENSSL_NO_ENGINE\n        else if (!strcmp(*argv, "-engine")) {\n            if (--argc < 1)\n                badarg = 1;\n            else\n                e = setup_engine(bio_err, *(++argv), 0);\n        }\n#endif\n        else if (!strcmp(*argv, "-pubin"))\n            key_type = KEY_PUBKEY;\n        else if (!strcmp(*argv, "-certin"))\n            key_type = KEY_CERT;\n        else if (!strcmp(*argv, "-asn1parse"))\n            asn1parse = 1;\n        else if (!strcmp(*argv, "-hexdump"))\n            hexdump = 1;\n        else if (!strcmp(*argv, "-sign"))\n            pkey_op = EVP_PKEY_OP_SIGN;\n        else if (!strcmp(*argv, "-verify"))\n            pkey_op = EVP_PKEY_OP_VERIFY;\n        else if (!strcmp(*argv, "-verifyrecover"))\n            pkey_op = EVP_PKEY_OP_VERIFYRECOVER;\n        else if (!strcmp(*argv, "-rev"))\n            rev = 1;\n        else if (!strcmp(*argv, "-encrypt"))\n            pkey_op = EVP_PKEY_OP_ENCRYPT;\n        else if (!strcmp(*argv, "-decrypt"))\n            pkey_op = EVP_PKEY_OP_DECRYPT;\n        else if (!strcmp(*argv, "-derive"))\n            pkey_op = EVP_PKEY_OP_DERIVE;\n        else if (strcmp(*argv, "-pkeyopt") == 0) {\n            if (--argc < 1)\n                badarg = 1;\n            else if (!ctx) {\n                BIO_puts(bio_err, "-pkeyopt command before -inkey\\n");\n                badarg = 1;\n            } else if (pkey_ctrl_string(ctx, *(++argv)) <= 0) {\n                BIO_puts(bio_err, "parameter setting error\\n");\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        } else\n            badarg = 1;\n        if (badarg) {\n            usage();\n            goto end;\n        }\n        argc--;\n        argv++;\n    }\n    if (!ctx) {\n        usage();\n        goto end;\n    }\n    if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY)) {\n        BIO_puts(bio_err, "Signature file specified for non verify\\n");\n        goto end;\n    }\n    if (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY)) {\n        BIO_puts(bio_err, "No signature file specified for verify\\n");\n        goto end;\n    }\n    app_RAND_load_file(NULL, bio_err, 0);\n    if (pkey_op != EVP_PKEY_OP_DERIVE) {\n        if (infile) {\n            if (!(in = BIO_new_file(infile, "rb"))) {\n                BIO_puts(bio_err, "Error Opening Input File\\n");\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        } else\n            in = BIO_new_fp(stdin, BIO_NOCLOSE);\n    }\n    if (outfile) {\n        if (!(out = BIO_new_file(outfile, "wb"))) {\n            BIO_printf(bio_err, "Error Creating Output File\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    } else {\n        out = BIO_new_fp(stdout, BIO_NOCLOSE);\n#ifdef OPENSSL_SYS_VMS\n        {\n            BIO *tmpbio = BIO_new(BIO_f_linebuffer());\n            out = BIO_push(tmpbio, out);\n        }\n#endif\n    }\n    if (sigfile) {\n        BIO *sigbio = BIO_new_file(sigfile, "rb");\n        if (!sigbio) {\n            BIO_printf(bio_err, "Can\'t open signature file %s\\n", sigfile);\n            goto end;\n        }\n        siglen = bio_to_mem(&sig, keysize * 10, sigbio);\n        BIO_free(sigbio);\n        if (siglen <= 0) {\n            BIO_printf(bio_err, "Error reading signature data\\n");\n            goto end;\n        }\n    }\n    if (in) {\n        buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);\n        if (buf_inlen <= 0) {\n            BIO_printf(bio_err, "Error reading input Data\\n");\n            exit(1);\n        }\n        if (rev) {\n            size_t i;\n            unsigned char ctmp;\n            size_t l = (size_t)buf_inlen;\n            for (i = 0; i < l / 2; i++) {\n                ctmp = buf_in[i];\n                buf_in[i] = buf_in[l - 1 - i];\n                buf_in[l - 1 - i] = ctmp;\n            }\n        }\n    }\n    if (pkey_op == EVP_PKEY_OP_VERIFY) {\n        rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,\n                             buf_in, (size_t)buf_inlen);\n        if (rv == 0)\n            BIO_puts(out, "Signature Verification Failure\\n");\n        else if (rv == 1)\n            BIO_puts(out, "Signature Verified Successfully\\n");\n        if (rv >= 0)\n            goto end;\n    } else {\n        rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,\n                      buf_in, (size_t)buf_inlen);\n        if (rv > 0) {\n            buf_out = OPENSSL_malloc(buf_outlen);\n            if (!buf_out)\n                rv = -1;\n            else\n                rv = do_keyop(ctx, pkey_op,\n                              buf_out, (size_t *)&buf_outlen,\n                              buf_in, (size_t)buf_inlen);\n        }\n    }\n    if (rv <= 0) {\n        BIO_printf(bio_err, "Public Key operation error\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    ret = 0;\n    if (asn1parse) {\n        if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))\n            ERR_print_errors(bio_err);\n    } else if (hexdump)\n        BIO_dump(out, (char *)buf_out, buf_outlen);\n    else\n        BIO_write(out, buf_out, buf_outlen);\n end:\n    if (ctx)\n        EVP_PKEY_CTX_free(ctx);\n    BIO_free(in);\n    BIO_free_all(out);\n    if (buf_in)\n        OPENSSL_free(buf_in);\n    if (buf_out)\n        OPENSSL_free(buf_out);\n    if (sig)\n        OPENSSL_free(sig);\n    return ret;\n}']