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


test/sm2_internal_test.c:336:9: Call
334.       /* From draft-shen-sm2-ecdsa-02 */
335.       EC_GROUP *test_group =
336.           create_EC_group
               ^
337.           ("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3",
338.            "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498",

test/sm2_internal_test.c:79:1: Parameter `*cof_hex`
  77.   }
  78.   
  79. > static EC_GROUP *create_EC_group(const char *p_hex, const char *a_hex,
  80.                                    const char *b_hex, const char *x_hex,
  81.                                    const char *y_hex, const char *order_hex,

test/sm2_internal_test.c:115:17: Call
  113.   
  114.       if (!TEST_true(BN_hex2bn(&order, order_hex))
  115.               || !TEST_true(BN_hex2bn(&cof, cof_hex))
                         ^
  116.               || !TEST_true(EC_GROUP_set_generator(group, generator, order, cof)))
  117.           goto done;

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 `create_EC_group` 
    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 sm2_sig_test(void)\n{\n    int testresult = 0;\n    EC_GROUP *test_group =\n        create_EC_group\n        ("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3",\n         "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498",\n         "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A",\n         "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D",\n         "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2",\n         "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7",\n         "1");\n    if (!TEST_ptr(test_group))\n        goto done;\n    if (!TEST_true(test_sm2_sign(\n                        test_group,\n                        "ALICE123@YAHOO.COM",\n                        "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263",\n                        "message digest",\n                        "006CB28D99385C175C94F94E934817663FC176D925DD72B727260DBAAE1FB2F96F"\n                        "007c47811054c6f99613a578eb8453706ccb96384fe7df5c171671e760bfa8be3a",\n                        "40F1EC59F793D9F49E09DCEF49130D4194F79FB1EED2CAA55BACDB49C4E755D1",\n                        "6FC6DAC32C5D5CF10C77DFB20F7C2EB667A457872FB09EC56327A67EC7DEEBE7")))\n        goto done;\n    testresult = 1;\n done:\n    EC_GROUP_free(test_group);\n    return testresult;\n}', 'static EC_GROUP *create_EC_group(const char *p_hex, const char *a_hex,\n                                 const char *b_hex, const char *x_hex,\n                                 const char *y_hex, const char *order_hex,\n                                 const char *cof_hex)\n{\n    BIGNUM *p = NULL;\n    BIGNUM *a = NULL;\n    BIGNUM *b = NULL;\n    BIGNUM *g_x = NULL;\n    BIGNUM *g_y = NULL;\n    BIGNUM *order = NULL;\n    BIGNUM *cof = NULL;\n    EC_POINT *generator = NULL;\n    EC_GROUP *group = NULL;\n    int ok = 0;\n    if (!TEST_true(BN_hex2bn(&p, p_hex))\n            || !TEST_true(BN_hex2bn(&a, a_hex))\n            || !TEST_true(BN_hex2bn(&b, b_hex)))\n        goto done;\n    group = EC_GROUP_new_curve_GFp(p, a, b, NULL);\n    if (!TEST_ptr(group))\n        goto done;\n    generator = EC_POINT_new(group);\n    if (!TEST_ptr(generator))\n        goto done;\n    if (!TEST_true(BN_hex2bn(&g_x, x_hex))\n            || !TEST_true(BN_hex2bn(&g_y, y_hex))\n            || !TEST_true(EC_POINT_set_affine_coordinates(group, generator, g_x,\n                                                          g_y, NULL)))\n        goto done;\n    if (!TEST_true(BN_hex2bn(&order, order_hex))\n            || !TEST_true(BN_hex2bn(&cof, cof_hex))\n            || !TEST_true(EC_GROUP_set_generator(group, generator, order, cof)))\n        goto done;\n    ok = 1;\ndone:\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    BN_free(g_x);\n    BN_free(g_y);\n    EC_POINT_free(generator);\n    BN_free(order);\n    BN_free(cof);\n    if (!ok) {\n        EC_GROUP_free(group);\n        group = NULL;\n    }\n    return group;\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}"]