test/dhtest.c:415: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_bin2bn`.
Showing all 14 steps of the trace


test/dhtest.c:414:14: Call
412.               goto bad_err;
413.   
414.           if (!TEST_ptr(priv_key = BN_bin2bn(td->xA, td->xA_len, NULL))
                    ^
415.                   || !TEST_ptr(pub_key = BN_bin2bn(td->yA, td->yA_len, NULL))
416.                   || !TEST_true(DH_set0_key(dhA, pub_key, priv_key)))

crypto/bn/bn_lib.c:407:1: Parameter `*ret->d`
  405.   }
  406.   
  407. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  408.   {
  409.       unsigned int i, m;

test/dhtest.c:415:21: Call
413.   
414.           if (!TEST_ptr(priv_key = BN_bin2bn(td->xA, td->xA_len, NULL))
415.                   || !TEST_ptr(pub_key = BN_bin2bn(td->yA, td->yA_len, NULL))
                           ^
416.                   || !TEST_true(DH_set0_key(dhA, pub_key, priv_key)))
417.               goto bad_err;

crypto/bn/bn_lib.c:407:1: Parameter `*ret->d`
  405.   }
  406.   
  407. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  408.   {
  409.       unsigned int i, m;

crypto/bn/bn_lib.c:429:9: Call
  427.       i = ((n - 1) / BN_BYTES) + 1;
  428.       m = ((n - 1) % (BN_BYTES));
  429.       if (bn_wexpand(ret, (int)i) == NULL) {
                 ^
  430.           BN_free(bn);
  431.           return NULL;

crypto/bn/bn_lib.c:948:1: Parameter `*a->d`
    946.   }
    947.   
    948. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    949.   {
    950.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:950:37: Call
    948.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    949.   {
    950.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                               ^
    951.   }
    952.   

crypto/bn/bn_lib.c:284:1: Parameter `*b->d`
      282.    */
      283.   
      284. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      285.   {
      286.       bn_check_top(b);

crypto/bn/bn_lib.c:289:23: Call
      287.   
      288.       if (words > b->dmax) {
      289.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      290.           if (!a)
      291.               return NULL;

crypto/bn/bn_lib.c:246:1: <Offset trace>
244.   /* This is used by bn_expand2() */
245.   /* The caller MUST check that words > b->dmax before calling this */
246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
247.   {
248.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:246:1: Parameter `b->top`
        244.   /* This is used by bn_expand2() */
        245.   /* The caller MUST check that words > b->dmax before calling this */
        246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        247.   {
        248.       BN_ULONG *a = NULL;

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

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

crypto/bn/bn_lib.c:271:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_bin2bn` 
        269.       assert(b->top <= words);
        270.       if (b->top > 0)
        271.           memcpy(a, b->d, sizeof(*a) * b->top);
                       ^
        272.   
        273.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    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 = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['static int rfc5114_test(void)\n{\n    int i;\n    DH *dhA = NULL;\n    DH *dhB = NULL;\n    unsigned char *Z1 = NULL;\n    unsigned char *Z2 = NULL;\n    const rfc5114_td *td = NULL;\n    BIGNUM *bady = NULL, *priv_key = NULL, *pub_key = NULL;\n    const BIGNUM *pub_key_tmp;\n    for (i = 0; i < (int)OSSL_NELEM(rfctd); i++) {\n        td = rfctd + i;\n        if (!TEST_ptr(dhA = td->get_param())\n                || !TEST_ptr(dhB = td->get_param()))\n            goto bad_err;\n        if (!TEST_ptr(priv_key = BN_bin2bn(td->xA, td->xA_len, NULL))\n                || !TEST_ptr(pub_key = BN_bin2bn(td->yA, td->yA_len, NULL))\n                || !TEST_true(DH_set0_key(dhA, pub_key, priv_key)))\n            goto bad_err;\n        if (!TEST_ptr(priv_key = BN_bin2bn(td->xB, td->xB_len, NULL))\n                || !TEST_ptr(pub_key = BN_bin2bn(td->yB, td->yB_len, NULL))\n                || !TEST_true( DH_set0_key(dhB, pub_key, priv_key)))\n            goto bad_err;\n        priv_key = pub_key = NULL;\n        if (!TEST_uint_eq(td->Z_len, (size_t)DH_size(dhA))\n            || !TEST_uint_eq(td->Z_len, (size_t)DH_size(dhB)))\n            goto err;\n        if (!TEST_ptr(Z1 = OPENSSL_malloc(DH_size(dhA)))\n                || !TEST_ptr(Z2 = OPENSSL_malloc(DH_size(dhB))))\n            goto bad_err;\n        DH_get0_key(dhB, &pub_key_tmp, NULL);\n        if (!TEST_int_ne(DH_compute_key(Z1, pub_key_tmp, dhA), -1))\n            goto bad_err;\n        DH_get0_key(dhA, &pub_key_tmp, NULL);\n        if (!TEST_int_ne(DH_compute_key(Z2, pub_key_tmp, dhB), -1))\n            goto bad_err;\n        if (!TEST_mem_eq(Z1, td->Z_len, td->Z, td->Z_len)\n                || !TEST_mem_eq(Z2, td->Z_len, td->Z, td->Z_len))\n            goto err;\n        DH_free(dhA);\n        dhA = NULL;\n        DH_free(dhB);\n        dhB = NULL;\n        OPENSSL_free(Z1);\n        Z1 = NULL;\n        OPENSSL_free(Z2);\n        Z2 = NULL;\n    }\n    if (!TEST_ptr(dhA = DH_get_2048_224())\n            || !TEST_ptr(Z1 = OPENSSL_malloc(DH_size(dhA))))\n        goto bad_err;\n    if (!TEST_ptr(bady = BN_bin2bn(dhtest_rfc5114_2048_224_bad_y,\n                                   sizeof(dhtest_rfc5114_2048_224_bad_y),\n                                   NULL)))\n        goto bad_err;\n    if (!DH_generate_key(dhA))\n        goto bad_err;\n    if (DH_compute_key(Z1, bady, dhA) != -1) {\n        goto err;\n    }\n    ERR_clear_error();\n    BN_free(bady);\n    DH_free(dhA);\n    OPENSSL_free(Z1);\n    return 1;\n bad_err:\n    BN_free(bady);\n    DH_free(dhA);\n    DH_free(dhB);\n    BN_free(pub_key);\n    BN_free(priv_key);\n    OPENSSL_free(Z1);\n    OPENSSL_free(Z2);\n    TEST_error("Initialisation error RFC5114 set %d\\n", i + 1);\n    return 0;\n err:\n    BN_free(bady);\n    DH_free(dhA);\n    DH_free(dhB);\n    OPENSSL_free(Z1);\n    OPENSSL_free(Z2);\n    TEST_error("Test failed RFC5114 set %d\\n", i + 1);\n    return 0;\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 = NULL;\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 = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}']