test/bntest.c:841: error: BUFFER_OVERRUN_L2
  Offset: [0, 536870912] (⇐ [0, 1] + [0, 536870911]) Size: 257 by call to `BN_hex2bn`.
Showing all 6 steps of the trace


test/bntest.c:841:5: Call
839.   
840.       /* Regression test for carry bug in mulx4x_mont */
841.       BN_hex2bn(&a,
           ^
842.           "7878787878787878787878787878787878787878787878787878787878787878"
843.           "7878787878787878787878787878787878787878787878787878787878787878"

crypto/bn/bn_print.c:141:10: <Offset trace>
139.       }
140.   
141.       for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)
                ^
142.           continue;
143.   

crypto/bn/bn_print.c:141:10: Assignment
  139.       }
  140.   
  141.       for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)
                  ^
  142.           continue;
  143.   

crypto/bn/bn_print.c:126:1: <Length trace>
124.   }
125.   
126. > int BN_hex2bn(BIGNUM **bn, const char *a)
127.   {
128.       BIGNUM *ret = NULL;

crypto/bn/bn_print.c:126:1: Parameter `*a`
  124.   }
  125.   
  126. > int BN_hex2bn(BIGNUM **bn, const char *a)
  127.   {
  128.       BIGNUM *ret = NULL;

crypto/bn/bn_print.c:141:37: Array access: Offset: [0, 536870912] (⇐ [0, 1] + [0, 536870911]) Size: 257 by call to `BN_hex2bn` 
  139.       }
  140.   
  141.       for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)
                                             ^
  142.           continue;
  143.   

int BN_hex2bn(BIGNUM **bn, const char *a)
{
    BIGNUM *ret = NULL;
    BN_ULONG l = 0;
    int neg = 0, h, m, i, j, k, c;
    int num;
    if ((a == NULL) || (*a == '\0'))
        return (0);
    if (*a == '-') {
        neg = 1;
        a++;
    }
    for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)
        continue;
    if (i == 0 || i > INT_MAX/4)
        goto err;
    num = i + neg;
    if (bn == NULL)
        return (num);
    if (*bn == NULL) {
        if ((ret = BN_new()) == NULL)
            return (0);
    } else {
        ret = *bn;
        BN_zero(ret);
    }
    if (bn_expand(ret, i * 4) == NULL)
        goto err;
    j = i;
    m = 0;
    h = 0;
    while (j > 0) {
        m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;
        l = 0;
        for (;;) {
            c = a[j - m];
            k = OPENSSL_hexchar2int(c);
            if (k < 0)
                k = 0;
            l = (l << 4) | k;
            if (--m <= 0) {
                ret->d[h++] = l;
                break;
            }
        }
        j -= (BN_BYTES * 2);
    }
    ret->top = h;
    bn_correct_top(ret);
    *bn = ret;
    bn_check_top(ret);
    if (ret->top != 0)
        ret->neg = neg;
    return (num);
 err:
    if (*bn == NULL)
        BN_free(ret);
    return (0);
}
['int test_mont(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *b, *c, *d, *A, *B;\n    BIGNUM *n;\n    int i;\n    BN_MONT_CTX *mont;\n    a = BN_new();\n    b = BN_new();\n    c = BN_new();\n    d = BN_new();\n    A = BN_new();\n    B = BN_new();\n    n = BN_new();\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL)\n        return 0;\n    BN_zero(n);\n    if (BN_MONT_CTX_set(mont, n, ctx)) {\n        fprintf(stderr, "BN_MONT_CTX_set succeeded for zero modulus!\\n");\n        return 0;\n    }\n    BN_set_word(n, 16);\n    if (BN_MONT_CTX_set(mont, n, ctx)) {\n        fprintf(stderr, "BN_MONT_CTX_set succeeded for even modulus!\\n");\n        return 0;\n    }\n    BN_bntest_rand(a, 100, 0, 0);\n    BN_bntest_rand(b, 100, 0, 0);\n    for (i = 0; i < num2; i++) {\n        int bits = (200 * (i + 1)) / num2;\n        if (bits == 0)\n            continue;\n        BN_bntest_rand(n, bits, 0, 1);\n        BN_MONT_CTX_set(mont, n, ctx);\n        BN_nnmod(a, a, n, ctx);\n        BN_nnmod(b, b, n, ctx);\n        BN_to_montgomery(A, a, mont, ctx);\n        BN_to_montgomery(B, b, mont, ctx);\n        BN_mod_mul_montgomery(c, A, B, mont, ctx);\n        BN_from_montgomery(A, c, mont, ctx);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " * ");\n                BN_print(bp, b);\n                BIO_puts(bp, " % ");\n                BN_print(bp, &mont->N);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, A);\n            BIO_puts(bp, "\\n");\n        }\n        BN_mod_mul(d, a, b, n, ctx);\n        BN_sub(d, d, A);\n        if (!BN_is_zero(d)) {\n            fprintf(stderr, "Montgomery multiplication test failed!\\n");\n            return 0;\n        }\n    }\n    BN_hex2bn(&a,\n        "7878787878787878787878787878787878787878787878787878787878787878"\n        "7878787878787878787878787878787878787878787878787878787878787878"\n        "7878787878787878787878787878787878787878787878787878787878787878"\n        "7878787878787878787878787878787878787878787878787878787878787878");\n    BN_hex2bn(&b,\n        "095D72C08C097BA488C5E439C655A192EAFB6380073D8C2664668EDDB4060744"\n        "E16E57FB4EDB9AE10A0CEFCDC28A894F689A128379DB279D48A2E20849D68593"\n        "9B7803BCF46CEBF5C533FB0DD35B080593DE5472E3FE5DB951B8BFF9B4CB8F03"\n        "9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81");\n    BN_hex2bn(&n,\n        "D78AF684E71DB0C39CFF4E64FB9DB567132CB9C50CC98009FEB820B26F2DED9B"\n        "91B9B5E2B83AE0AE4EB4E0523CA726BFBE969B89FD754F674CE99118C3F2D1C5"\n        "D81FDC7C54E02B60262B241D53C040E99E45826ECA37A804668E690E1AFC1CA4"\n        "2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF");\n    BN_MONT_CTX_set(mont, n, ctx);\n    BN_mod_mul_montgomery(c, a, b, mont, ctx);\n    BN_mod_mul_montgomery(d, b, a, mont, ctx);\n    if (BN_cmp(c, d)) {\n        fprintf(stderr, "Montgomery multiplication test failed:"\n                        " a*b != b*a.\\n");\n        return 0;\n    }\n    BN_MONT_CTX_free(mont);\n    BN_free(a);\n    BN_free(b);\n    BN_free(c);\n    BN_free(d);\n    BN_free(A);\n    BN_free(B);\n    BN_free(n);\n    return (1);\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n    BIGNUM *ret = NULL;\n    BN_ULONG l = 0;\n    int neg = 0, h, m, i, j, k, c;\n    int num;\n    if ((a == NULL) || (*a == '\\0'))\n        return (0);\n    if (*a == '-') {\n        neg = 1;\n        a++;\n    }\n    for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)\n        continue;\n    if (i == 0 || i > INT_MAX/4)\n        goto err;\n    num = i + neg;\n    if (bn == NULL)\n        return (num);\n    if (*bn == NULL) {\n        if ((ret = BN_new()) == NULL)\n            return (0);\n    } else {\n        ret = *bn;\n        BN_zero(ret);\n    }\n    if (bn_expand(ret, i * 4) == NULL)\n        goto err;\n    j = i;\n    m = 0;\n    h = 0;\n    while (j > 0) {\n        m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;\n        l = 0;\n        for (;;) {\n            c = a[j - m];\n            k = OPENSSL_hexchar2int(c);\n            if (k < 0)\n                k = 0;\n            l = (l << 4) | k;\n            if (--m <= 0) {\n                ret->d[h++] = l;\n                break;\n            }\n        }\n        j -= (BN_BYTES * 2);\n    }\n    ret->top = h;\n    bn_correct_top(ret);\n    *bn = ret;\n    bn_check_top(ret);\n    if (ret->top != 0)\n        ret->neg = neg;\n    return (num);\n err:\n    if (*bn == NULL)\n        BN_free(ret);\n    return (0);\n}"]