crypto/pem/pvkfmt.c:767: error: BUFFER_OVERRUN_L3
  Offset added: [9, +oo] (⇐ [1, +oo] + 8) Size: [8, +oo] by call to `do_PVK_body`.
Showing all 7 steps of the trace


crypto/pem/pvkfmt.c:754:10: Call
752.       p = pvk_hdr;
753.   
754.       if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen))
                ^
755.           return 0;
756.       buflen = (int)keylen + saltlen;

crypto/pem/pvkfmt.c:609:1: Parameter `*psaltlen`
  607.   # ifndef OPENSSL_NO_RC4
  608.   
  609. > static int do_PVK_header(const unsigned char **in, unsigned int length,
  610.                            int skip_magic,
  611.                            unsigned int *psaltlen, unsigned int *pkeylen)

crypto/pem/pvkfmt.c:767:11: Call
765.           goto err;
766.       }
767.       ret = do_PVK_body(&p, saltlen, keylen, cb, u);
                 ^
768.   
769.    err:

crypto/pem/pvkfmt.c:666:1: <Length trace>
664.   }
665.   
666. > static EVP_PKEY *do_PVK_body(const unsigned char **in,
667.                                unsigned int saltlen, unsigned int keylen,
668.                                pem_password_cb *cb, void *u)

crypto/pem/pvkfmt.c:666:1: Parameter `saltlen`
  664.   }
  665.   
  666. > static EVP_PKEY *do_PVK_body(const unsigned char **in,
  667.                                unsigned int saltlen, unsigned int keylen,
  668.                                pem_password_cb *cb, void *u)

crypto/pem/pvkfmt.c:697:9: Assignment
  695.                               (unsigned char *)psbuf, inlen))
  696.               goto err;
  697.           p += saltlen;
                 ^
  698.           /* Copy BLOBHEADER across, decrypt rest */
  699.           memcpy(enctmp, p, 8);

crypto/pem/pvkfmt.c:699:9: Array access: Offset added: [9, +oo] (⇐ [1, +oo] + 8) Size: [8, +oo] by call to `do_PVK_body` 
  697.           p += saltlen;
  698.           /* Copy BLOBHEADER across, decrypt rest */
  699.           memcpy(enctmp, p, 8);
                 ^
  700.           p += 8;
  701.           if (keylen < 8) {

static EVP_PKEY *do_PVK_body(const unsigned char **in,
                             unsigned int saltlen, unsigned int keylen,
                             pem_password_cb *cb, void *u)
{
    EVP_PKEY *ret = NULL;
    const unsigned char *p = *in;
    unsigned int magic;
    unsigned char *enctmp = NULL, *q;
    EVP_CIPHER_CTX cctx;
    EVP_CIPHER_CTX_init(&cctx);
    if (saltlen) {
        char psbuf[PEM_BUFSIZE];
        unsigned char keybuf[20];
        int enctmplen, inlen;
        if (cb)
            inlen = cb(psbuf, PEM_BUFSIZE, 0, u);
        else
            inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
        if (inlen <= 0) {
            PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_PASSWORD_READ);
            goto err;
        }
        enctmp = OPENSSL_malloc(keylen + 8);
        if (enctmp == NULL) {
            PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        if (!derive_pvk_key(keybuf, p, saltlen,
                            (unsigned char *)psbuf, inlen))
            goto err;
        p += saltlen;
        memcpy(enctmp, p, 8);
        p += 8;
        if (keylen < 8) {
            PEMerr(PEM_F_DO_PVK_BODY, PEM_R_PVK_TOO_SHORT);
            goto err;
        }
        inlen = keylen - 8;
        q = enctmp + 8;
        if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))
            goto err;
        if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))
            goto err;
        if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen))
            goto err;
        magic = read_ledword((const unsigned char **)&q);
        if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC) {
            q = enctmp + 8;
            memset(keybuf + 5, 0, 11);
            if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))
                goto err;
            OPENSSL_cleanse(keybuf, 20);
            if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))
                goto err;
            if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen))
                goto err;
            magic = read_ledword((const unsigned char **)&q);
            if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC) {
                PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_DECRYPT);
                goto err;
            }
        } else
            OPENSSL_cleanse(keybuf, 20);
        p = enctmp;
    }
    ret = b2i_PrivateKey(&p, keylen);
 err:
    EVP_CIPHER_CTX_cleanup(&cctx);
    OPENSSL_free(enctmp);
    return ret;
}
['EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)\n{\n    unsigned char pvk_hdr[24], *buf = NULL;\n    const unsigned char *p;\n    int buflen;\n    EVP_PKEY *ret = NULL;\n    unsigned int saltlen, keylen;\n    if (BIO_read(in, pvk_hdr, 24) != 24) {\n        PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT);\n        return NULL;\n    }\n    p = pvk_hdr;\n    if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen))\n        return 0;\n    buflen = (int)keylen + saltlen;\n    buf = OPENSSL_malloc(buflen);\n    if (buf == NULL) {\n        PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    p = buf;\n    if (BIO_read(in, buf, buflen) != buflen) {\n        PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT);\n        goto err;\n    }\n    ret = do_PVK_body(&p, saltlen, keylen, cb, u);\n err:\n    OPENSSL_clear_free(buf, buflen);\n    return ret;\n}', 'static int do_PVK_header(const unsigned char **in, unsigned int length,\n                         int skip_magic,\n                         unsigned int *psaltlen, unsigned int *pkeylen)\n{\n    const unsigned char *p = *in;\n    unsigned int pvk_magic, is_encrypted;\n    if (skip_magic) {\n        if (length < 20) {\n            PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);\n            return 0;\n        }\n    } else {\n        if (length < 24) {\n            PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);\n            return 0;\n        }\n        pvk_magic = read_ledword(&p);\n        if (pvk_magic != MS_PVKMAGIC) {\n            PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER);\n            return 0;\n        }\n    }\n    p += 4;\n      read_ledword(&p);\n    is_encrypted = read_ledword(&p);\n    *psaltlen = read_ledword(&p);\n    *pkeylen = read_ledword(&p);\n    if (is_encrypted && !*psaltlen) {\n        PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER);\n        return 0;\n    }\n    *in = p;\n    return 1;\n}', 'static EVP_PKEY *do_PVK_body(const unsigned char **in,\n                             unsigned int saltlen, unsigned int keylen,\n                             pem_password_cb *cb, void *u)\n{\n    EVP_PKEY *ret = NULL;\n    const unsigned char *p = *in;\n    unsigned int magic;\n    unsigned char *enctmp = NULL, *q;\n    EVP_CIPHER_CTX cctx;\n    EVP_CIPHER_CTX_init(&cctx);\n    if (saltlen) {\n        char psbuf[PEM_BUFSIZE];\n        unsigned char keybuf[20];\n        int enctmplen, inlen;\n        if (cb)\n            inlen = cb(psbuf, PEM_BUFSIZE, 0, u);\n        else\n            inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);\n        if (inlen <= 0) {\n            PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_PASSWORD_READ);\n            goto err;\n        }\n        enctmp = OPENSSL_malloc(keylen + 8);\n        if (enctmp == NULL) {\n            PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if (!derive_pvk_key(keybuf, p, saltlen,\n                            (unsigned char *)psbuf, inlen))\n            goto err;\n        p += saltlen;\n        memcpy(enctmp, p, 8);\n        p += 8;\n        if (keylen < 8) {\n            PEMerr(PEM_F_DO_PVK_BODY, PEM_R_PVK_TOO_SHORT);\n            goto err;\n        }\n        inlen = keylen - 8;\n        q = enctmp + 8;\n        if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))\n            goto err;\n        if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))\n            goto err;\n        if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen))\n            goto err;\n        magic = read_ledword((const unsigned char **)&q);\n        if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC) {\n            q = enctmp + 8;\n            memset(keybuf + 5, 0, 11);\n            if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))\n                goto err;\n            OPENSSL_cleanse(keybuf, 20);\n            if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))\n                goto err;\n            if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen))\n                goto err;\n            magic = read_ledword((const unsigned char **)&q);\n            if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC) {\n                PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_DECRYPT);\n                goto err;\n            }\n        } else\n            OPENSSL_cleanse(keybuf, 20);\n        p = enctmp;\n    }\n    ret = b2i_PrivateKey(&p, keylen);\n err:\n    EVP_CIPHER_CTX_cleanup(&cctx);\n    OPENSSL_free(enctmp);\n    return ret;\n}']