crypto/pkcs12/p12_key.c:186: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_bin2bn`.
Showing all 13 steps of the trace


crypto/pkcs12/p12_key.c:181:14: Call
179.               B[j] = Ai[j % u];
180.           /* Work out B + 1 first then can use B as tmp space */
181.           if (!BN_bin2bn(B, v, Bpl1))
                    ^
182.               goto err;
183.           if (!BN_add_word(Bpl1, 1))

crypto/bn/bn_lib.c:541:1: Parameter `*ret->d`
  539.   }
  540.   
  541. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  542.   {
  543.       unsigned int i, m;

crypto/pkcs12/p12_key.c:186:18: Call
184.               goto err;
185.           for (j = 0; j < Ilen; j += v) {
186.               if (!BN_bin2bn(I + j, v, Ij))
                        ^
187.                   goto err;
188.               if (!BN_add(Ij, Ij, Bpl1))

crypto/bn/bn_lib.c:541:1: Parameter `*ret->d`
  539.   }
  540.   
  541. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  542.   {
  543.       unsigned int i, m;

crypto/bn/bn_lib.c:563:9: Call
  561.       i = ((n - 1) / BN_BYTES) + 1;
  562.       m = ((n - 1) % (BN_BYTES));
  563.       if (bn_wexpand(ret, (int)i) == NULL) {
                 ^
  564.           BN_free(bn);
  565.           return NULL;

crypto/bn/bn_lib.c:994:1: Parameter `*a->d`
    992.   }
    993.   
    994. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    995.   {
    996.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:996:37: Call
    994.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    995.   {
    996.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                               ^
    997.   }
    998.   

crypto/bn/bn_lib.c:389:1: Parameter `*b->d`
      387.    */
      388.   
      389. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      390.   {
      391.       bn_check_top(b);

crypto/bn/bn_lib.c:394:23: Call
      392.   
      393.       if (words > b->dmax) {
      394.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      395.           if (!a)
      396.               return NULL;

crypto/bn/bn_lib.c:299:1: <Length trace>
297.   /* This is used by bn_expand2() */
298.   /* The caller MUST check that words > b->dmax before calling this */
299. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
300.   {
301.       BN_ULONG *A, *a = NULL;

crypto/bn/bn_lib.c:299:1: Parameter `*b->d`
        297.   /* This is used by bn_expand2() */
        298.   /* The caller MUST check that words > b->dmax before calling this */
        299. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        300.   {
        301.       BN_ULONG *A, *a = NULL;

crypto/bn/bn_lib.c:334:5: Assignment
        332.   
        333.   #if 1
        334.       B = b->d;
                   ^
        335.       /* Check if the previous number needs to be copied */
        336.       if (B != NULL) {

crypto/bn/bn_lib.c:351:18: Array access: Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_bin2bn` 
        349.               a1 = B[1];
        350.               a2 = B[2];
        351.               a3 = B[3];
                                ^
        352.               A[0] = a0;
        353.               A[1] = a1;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *A, *a = NULL;
    const BN_ULONG *B;
    int i;
    bn_check_top(b);
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return (NULL);
    }
    if (BN_get_flags(b,BN_FLG_SECURE))
        a = A = OPENSSL_secure_malloc(words * sizeof(*a));
    else
        a = A = OPENSSL_malloc(words * sizeof(*a));
    if (A == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
#ifdef PURIFY
    memset(a, 0, sizeof(*a) * words);
#endif
#if 1
    B = b->d;
    if (B != NULL) {
        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
            BN_ULONG a0, a1, a2, a3;
            a0 = B[0];
            a1 = B[1];
            a2 = B[2];
            a3 = B[3];
            A[0] = a0;
            A[1] = a1;
            A[2] = a2;
            A[3] = a3;
        }
        switch (b->top & 3) {
        case 3:
            A[2] = B[2];
        case 2:
            A[1] = B[1];
        case 1:
            A[0] = B[0];
        case 0:
            ;
        }
    }
#else
    memset(A, 0, sizeof(*A) * words);
    memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
    return (a);
}
['int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,\n                       int saltlen, int id, int iter, int n,\n                       unsigned char *out, const EVP_MD *md_type)\n{\n    unsigned char *B = NULL, *D = NULL, *I = NULL, *p = NULL, *Ai = NULL;\n    int Slen, Plen, Ilen, Ijlen;\n    int i, j, u, v;\n    int ret = 0;\n    BIGNUM *Ij = NULL, *Bpl1 = NULL;\n    EVP_MD_CTX *ctx = NULL;\n#ifdef  DEBUG_KEYGEN\n    unsigned char *tmpout = out;\n    int tmpn = n;\n#endif\n    ctx = EVP_MD_CTX_new();\n    if (ctx == NULL)\n        goto err;\n#ifdef  DEBUG_KEYGEN\n    fprintf(stderr, "KEYGEN DEBUG\\n");\n    fprintf(stderr, "ID %d, ITER %d\\n", id, iter);\n    fprintf(stderr, "Password (length %d):\\n", passlen);\n    h__dump(pass, passlen);\n    fprintf(stderr, "Salt (length %d):\\n", saltlen);\n    h__dump(salt, saltlen);\n#endif\n    v = EVP_MD_block_size(md_type);\n    u = EVP_MD_size(md_type);\n    if (u < 0)\n        return 0;\n    D = OPENSSL_malloc(v);\n    Ai = OPENSSL_malloc(u);\n    B = OPENSSL_malloc(v + 1);\n    Slen = v * ((saltlen + v - 1) / v);\n    if (passlen)\n        Plen = v * ((passlen + v - 1) / v);\n    else\n        Plen = 0;\n    Ilen = Slen + Plen;\n    I = OPENSSL_malloc(Ilen);\n    Ij = BN_new();\n    Bpl1 = BN_new();\n    if (D == NULL || Ai == NULL || B == NULL || I == NULL || Ij == NULL\n            || Bpl1 == NULL)\n        goto err;\n    for (i = 0; i < v; i++)\n        D[i] = id;\n    p = I;\n    for (i = 0; i < Slen; i++)\n        *p++ = salt[i % saltlen];\n    for (i = 0; i < Plen; i++)\n        *p++ = pass[i % passlen];\n    for (;;) {\n        if (!EVP_DigestInit_ex(ctx, md_type, NULL)\n            || !EVP_DigestUpdate(ctx, D, v)\n            || !EVP_DigestUpdate(ctx, I, Ilen)\n            || !EVP_DigestFinal_ex(ctx, Ai, NULL))\n            goto err;\n        for (j = 1; j < iter; j++) {\n            if (!EVP_DigestInit_ex(ctx, md_type, NULL)\n                || !EVP_DigestUpdate(ctx, Ai, u)\n                || !EVP_DigestFinal_ex(ctx, Ai, NULL))\n                goto err;\n        }\n        memcpy(out, Ai, min(n, u));\n        if (u >= n) {\n#ifdef DEBUG_KEYGEN\n            fprintf(stderr, "Output KEY (length %d)\\n", tmpn);\n            h__dump(tmpout, tmpn);\n#endif\n            ret = 1;\n            goto end;\n        }\n        n -= u;\n        out += u;\n        for (j = 0; j < v; j++)\n            B[j] = Ai[j % u];\n        if (!BN_bin2bn(B, v, Bpl1))\n            goto err;\n        if (!BN_add_word(Bpl1, 1))\n            goto err;\n        for (j = 0; j < Ilen; j += v) {\n            if (!BN_bin2bn(I + j, v, Ij))\n                goto err;\n            if (!BN_add(Ij, Ij, Bpl1))\n                goto err;\n            if (!BN_bn2bin(Ij, B))\n                goto err;\n            Ijlen = BN_num_bytes(Ij);\n            if (Ijlen > v) {\n                if (!BN_bn2bin(Ij, B))\n                    goto err;\n                memcpy(I + j, B + 1, v);\n#ifndef PKCS12_BROKEN_KEYGEN\n            } else if (Ijlen < v) {\n                memset(I + j, 0, v - Ijlen);\n                if (!BN_bn2bin(Ij, I + j + v - Ijlen))\n                    goto err;\n#endif\n            } else if (!BN_bn2bin(Ij, I + j))\n                goto err;\n        }\n    }\n err:\n    PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE);\n end:\n    OPENSSL_free(Ai);\n    OPENSSL_free(B);\n    OPENSSL_free(D);\n    OPENSSL_free(I);\n    BN_free(Ij);\n    BN_free(Bpl1);\n    EVP_MD_CTX_free(ctx);\n    return ret;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return (NULL);\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return (ret);\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return (ret);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *A, *a = NULL;\n    const BN_ULONG *B;\n    int i;\n    bn_check_top(b);\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return (NULL);\n    }\n    if (BN_get_flags(b,BN_FLG_SECURE))\n        a = A = OPENSSL_secure_malloc(words * sizeof(*a));\n    else\n        a = A = OPENSSL_malloc(words * sizeof(*a));\n    if (A == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n#ifdef PURIFY\n    memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n    B = b->d;\n    if (B != NULL) {\n        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n            BN_ULONG a0, a1, a2, a3;\n            a0 = B[0];\n            a1 = B[1];\n            a2 = B[2];\n            a3 = B[3];\n            A[0] = a0;\n            A[1] = a1;\n            A[2] = a2;\n            A[3] = a3;\n        }\n        switch (b->top & 3) {\n        case 3:\n            A[2] = B[2];\n        case 2:\n            A[1] = B[1];\n        case 1:\n            A[0] = B[0];\n        case 0:\n            ;\n        }\n    }\n#else\n    memset(A, 0, sizeof(*A) * words);\n    memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    return (a);\n}']