test/bntest.c:1677: error: BUFFER_OVERRUN_L2
  Offset: [2, 536870915] (⇐ [2, 4] + [0, 536870911]) Size: 7 by call to `BN_asc2bn`.
Showing all 9 steps of the trace


test/bntest.c:1677:10: Call
1675.           goto err;
1676.   
1677.       if (!TEST_true(BN_asc2bn(&bn, "0x1234"))
                 ^
1678.               || !TEST_BN_eq_word(bn, 0x1234)
1679.               || !TEST_BN_ge_zero(bn))

crypto/bn/bn_print.c:267:1: Parameter `*a`
  265.   }
  266.   
  267. > int BN_asc2bn(BIGNUM **bn, const char *a)
  268.   {
  269.       const char *p = a;

crypto/bn/bn_print.c:269:5: Assignment
  267.   int BN_asc2bn(BIGNUM **bn, const char *a)
  268.   {
  269.       const char *p = a;
             ^
  270.   
  271.       if (*p == '-')

crypto/bn/bn_print.c:275:14: Call
  273.   
  274.       if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x')) {
  275.           if (!BN_hex2bn(bn, p + 2))
                      ^
  276.               return 0;
  277.       } else {

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

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

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

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

crypto/bn/bn_print.c:139:37: Array access: Offset: [2, 536870915] (⇐ [2, 4] + [0, 536870911]) Size: 7 by call to `BN_asc2bn` 
    137.       }
    138.   
    139.       for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)
                                               ^
    140.           continue;
    141.   

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);
}
['static int test_asc2bn()\n{\n    BIGNUM *bn = NULL;\n    int st = 0;\n    if (!TEST_ptr(bn = BN_new()))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "0"))\n            || !TEST_BN_eq_zero(bn)\n            || !TEST_BN_ge_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "256"))\n            || !TEST_BN_eq_word(bn, 256)\n            || !TEST_BN_ge_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "-42"))\n            || !TEST_BN_abs_eq_word(bn, 42)\n            || !TEST_BN_lt_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "0x1234"))\n            || !TEST_BN_eq_word(bn, 0x1234)\n            || !TEST_BN_ge_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "0X1234"))\n            || !TEST_BN_eq_word(bn, 0x1234)\n            || !TEST_BN_ge_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "-0xabcd"))\n            || !TEST_BN_abs_eq_word(bn, 0xabcd)\n            || !TEST_BN_lt_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "-0"))\n            || !TEST_BN_eq_zero(bn)\n            || !TEST_BN_ge_zero(bn))\n        goto err;\n    if (!TEST_true(BN_asc2bn(&bn, "123trailing garbage is ignored"))\n            || !TEST_BN_eq_word(bn, 123)\n            || !TEST_BN_ge_zero(bn))\n        goto err;\n    st = 1;\nerr:\n    BN_free(bn);\n    return st;\n}', "int BN_asc2bn(BIGNUM **bn, const char *a)\n{\n    const char *p = a;\n    if (*p == '-')\n        p++;\n    if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x')) {\n        if (!BN_hex2bn(bn, p + 2))\n            return 0;\n    } else {\n        if (!BN_dec2bn(bn, p))\n            return 0;\n    }\n    if (*a == '-' && (*bn)->top != 0)\n        (*bn)->neg = 1;\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}"]