test/bntest.c:1772: error: BUFFER_OVERRUN_L2
  Offset: [0, 536870912] (⇐ [0, 1] + [0, 536870911]) Size: 2 by call to `parseBN`.
Showing all 8 steps of the trace


test/bntest.c:1772:10: Call
1770.       int st = 0;
1771.   
1772.       if (!TEST_int_eq(parseBN(&bn, "0"), 1)
                 ^
1773.               || !TEST_BN_eq_zero(bn)
1774.               || !TEST_BN_ge_zero(bn)

test/bntest.c:85:1: Parameter `*in`
  83.    * Parse BIGNUM, return number of bytes parsed.
  84.    */
  85. > static int parseBN(BIGNUM **out, const char *in)
  86.   {
  87.       *out = NULL;

test/bntest.c:88:12: Call
  86.   {
  87.       *out = NULL;
  88.       return BN_hex2bn(out, in);
                   ^
  89.   }
  90.   

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

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

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

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

crypto/bn/bn_conv.c:141:37: Array access: Offset: [0, 536870912] (⇐ [0, 1] + [0, 536870911]) Size: 2 by call to `parseBN` 
    139.       }
    140.   
    141.       for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(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 && ossl_isxdigit(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;
}
['static int test_hex2bn(void)\n{\n    BIGNUM *bn = NULL;\n    int st = 0;\n    if (!TEST_int_eq(parseBN(&bn, "0"), 1)\n            || !TEST_BN_eq_zero(bn)\n            || !TEST_BN_ge_zero(bn)\n            || !TEST_BN_even(bn))\n        goto err;\n    BN_free(bn);\n    bn = NULL;\n    if (!TEST_int_eq(parseBN(&bn, "256"), 3)\n            || !TEST_BN_eq_word(bn, 0x256)\n            || !TEST_BN_ge_zero(bn)\n            || !TEST_BN_gt_zero(bn)\n            || !TEST_BN_ne_zero(bn)\n            || !TEST_BN_even(bn))\n        goto err;\n    BN_free(bn);\n    bn = NULL;\n    if (!TEST_int_eq(parseBN(&bn, "-42"), 3)\n            || !TEST_BN_abs_eq_word(bn, 0x42)\n            || !TEST_BN_lt_zero(bn)\n            || !TEST_BN_le_zero(bn)\n            || !TEST_BN_ne_zero(bn)\n            || !TEST_BN_even(bn))\n        goto err;\n    BN_free(bn);\n    bn = NULL;\n    if (!TEST_int_eq(parseBN(&bn, "cb"), 2)\n            || !TEST_BN_eq_word(bn, 0xCB)\n            || !TEST_BN_ge_zero(bn)\n            || !TEST_BN_gt_zero(bn)\n            || !TEST_BN_ne_zero(bn)\n            || !TEST_BN_odd(bn))\n        goto err;\n    BN_free(bn);\n    bn = NULL;\n    if (!TEST_int_eq(parseBN(&bn, "-0"), 2)\n            || !TEST_BN_eq_zero(bn)\n            || !TEST_BN_ge_zero(bn)\n            || !TEST_BN_le_zero(bn)\n            || !TEST_BN_even(bn))\n        goto err;\n    BN_free(bn);\n    bn = NULL;\n    if (!TEST_int_eq(parseBN(&bn, "abctrailing garbage is ignored"), 3)\n            || !TEST_BN_eq_word(bn, 0xabc)\n            || !TEST_BN_ge_zero(bn)\n            || !TEST_BN_gt_zero(bn)\n            || !TEST_BN_ne_zero(bn)\n            || !TEST_BN_even(bn))\n        goto err;\n    st = 1;\n err:\n    BN_free(bn);\n    return st;\n}', 'static int parseBN(BIGNUM **out, const char *in)\n{\n    *out = NULL;\n    return BN_hex2bn(out, in);\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 && ossl_isxdigit(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}"]