test/params_test.c:521: error: BUFFER_OVERRUN_L2
  Offset: [-15, 536870911] (⇐ [0, 1] + [-15, 536870910]) Size: 9 by call to `BN_hex2bn`.
Showing all 7 steps of the trace


test/params_test.c:521:10: Call
519.       verify_p3 = NULL;
520.   
521.       if (!TEST_true(BN_hex2bn(&verify_p3, app_p3_init))) {
                ^
522.           errcnt++;
523.           goto fin;

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:164:5: Assignment
  162.           goto err;
  163.   
  164.       j = i;                      /* least significant 'hex' */
             ^
  165.       m = 0;
  166.       h = 0;

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:171:17: Array access: Offset: [-15, 536870911] (⇐ [0, 1] + [-15, 536870910]) Size: 9 by call to `BN_hex2bn` 
  169.           l = 0;
  170.           for (;;) {
  171.               c = a[j - m];
                         ^
  172.               k = OPENSSL_hexchar2int(c);
  173.               if (k < 0)

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_case_variant(const OSSL_PARAM *params,\n                             const struct provider_dispatch_st *prov)\n{\n    BIGNUM *verify_p3 = NULL;\n    void *obj = NULL;\n    int errcnt = 0;\n    if (!TEST_ptr(obj = init_object())\n        || !TEST_true(BN_hex2bn(&verify_p3, p3_init))) {\n        errcnt++;\n        goto fin;\n    }\n    init_app_variables();\n    if (!TEST_true(prov->get_params(obj, params))\n        || !TEST_int_eq(app_p1, p1_init)\n        || !TEST_double_eq(app_p2, app_p2_init)\n        || !TEST_ptr(BN_native2bn(bignumbin, bignumbin_l, app_p3))\n        || !TEST_BN_eq(app_p3, verify_p3)\n        || !TEST_str_eq(app_p4, p4_init)\n        || !TEST_size_t_eq(app_p5_l, sizeof(p5_init))\n        || !TEST_str_eq(app_p5, p5_init)\n        || !TEST_size_t_eq(app_p6_l, sizeof(p6_init))\n        || !TEST_str_eq(app_p6, p6_init)\n        || !TEST_char_eq(foo[0], app_foo_init)\n        || !TEST_int_eq(foo_l, sizeof(app_foo_init)))\n        errcnt++;\n    init_app_variables();\n    if (!TEST_true(prov->set_params(obj, params))) {\n        errcnt++;\n    } else {\n        struct object_st *sneakpeek = obj;\n        if (!TEST_int_eq(sneakpeek->p1, app_p1)\n            || !TEST_double_eq(sneakpeek->p2, p2_init)\n            || !TEST_BN_eq(sneakpeek->p3, app_p3)\n            || !TEST_str_eq(sneakpeek->p4, app_p4)\n            || !TEST_size_t_eq(sneakpeek->p5_l, app_p5_l)\n            || !TEST_str_eq(sneakpeek->p5, app_p5)\n            || !TEST_size_t_eq(sneakpeek->p6_l,\n                               sizeof(app_p6_init))\n            || !TEST_str_eq(sneakpeek->p6, app_p6))\n            errcnt++;\n    }\n    BN_free(verify_p3);\n    verify_p3 = NULL;\n    if (!TEST_true(BN_hex2bn(&verify_p3, app_p3_init))) {\n        errcnt++;\n        goto fin;\n    }\n    if (!TEST_true(prov->get_params(obj, params))\n        || !TEST_int_eq(app_p1, app_p1_init)\n        || !TEST_double_eq(app_p2, app_p2_init)\n        || !TEST_ptr(BN_native2bn(bignumbin, bignumbin_l, app_p3))\n        || !TEST_BN_eq(app_p3, verify_p3)\n        || !TEST_str_eq(app_p4, app_p4_init)\n        || !TEST_size_t_eq(app_p5_l,\n                           sizeof(app_p5_init))\n        || !TEST_str_eq(app_p5, app_p5_init)\n        || !TEST_size_t_eq(app_p6_l,\n                           sizeof(app_p6_init))\n        || !TEST_str_eq(app_p6, app_p6_init)\n        || !TEST_char_eq(foo[0], app_foo_init)\n        || !TEST_int_eq(foo_l, sizeof(app_foo_init)))\n        errcnt++;\n fin:\n    BN_free(verify_p3);\n    verify_p3 = NULL;\n    cleanup_app_variables();\n    cleanup_object(obj);\n    return errcnt == 0;\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}"]