test/rsa_test.c:382: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_bin2bn`.
Showing all 14 steps of the trace


test/rsa_test.c:382:9: Call
380.        * RSA key is not used.  The 'd' parameter can be NULL safely.
381.        */
382.       if (TEST_true(RSA_set0_key(key, BN_bin2bn(num, bytes, NULL),
               ^
383.                                  BN_bin2bn(num, bytes, NULL), NULL))
384.               && TEST_uint_eq(RSA_security_bits(key), result))

crypto/bn/bn_lib.c:372:1: Parameter `*ret->d`
  370.   }
  371.   
  372. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  373.   {
  374.       unsigned int i, m;

test/rsa_test.c:382:9: Call
380.        * RSA key is not used.  The 'd' parameter can be NULL safely.
381.        */
382.       if (TEST_true(RSA_set0_key(key, BN_bin2bn(num, bytes, NULL),
               ^
383.                                  BN_bin2bn(num, bytes, NULL), NULL))
384.               && TEST_uint_eq(RSA_security_bits(key), result))

crypto/bn/bn_lib.c:372:1: Parameter `*ret->d`
  370.   }
  371.   
  372. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  373.   {
  374.       unsigned int i, m;

crypto/bn/bn_lib.c:394:9: Call
  392.       i = ((n - 1) / BN_BYTES) + 1;
  393.       m = ((n - 1) % (BN_BYTES));
  394.       if (bn_wexpand(ret, (int)i) == NULL) {
                 ^
  395.           BN_free(bn);
  396.           return NULL;

crypto/bn/bn_lib.c:962:1: Parameter `*a->d`
    960.   }
    961.   
    962. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    963.   {
    964.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:964:37: Call
    962.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    963.   {
    964.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                               ^
    965.   }
    966.   

crypto/bn/bn_lib.c:245:1: Parameter `*b->d`
      243.    */
      244.   
      245. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      246.   {
      247.       if (words > b->dmax) {

crypto/bn/bn_lib.c:248:23: Call
      246.   {
      247.       if (words > b->dmax) {
      248.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      249.           if (!a)
      250.               return NULL;

crypto/bn/bn_lib.c:209:1: <Offset trace>
207.   /* This is used by bn_expand2() */
208.   /* The caller MUST check that words > b->dmax before calling this */
209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
210.   {
211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: Parameter `b->top`
        207.   /* This is used by bn_expand2() */
        208.   /* The caller MUST check that words > b->dmax before calling this */
        209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        210.   {
        211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: <Length trace>
207.   /* This is used by bn_expand2() */
208.   /* The caller MUST check that words > b->dmax before calling this */
209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
210.   {
211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: Parameter `*b->d`
        207.   /* This is used by bn_expand2() */
        208.   /* The caller MUST check that words > b->dmax before calling this */
        209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        210.   {
        211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:232:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_bin2bn` 
        230.       assert(b->top <= words);
        231.       if (b->top > 0)
        232.           memcpy(a, b->d, sizeof(*a) * b->top);
                       ^
        233.   
        234.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['static int test_rsa_security_bit(int n)\n{\n    static const unsigned char vals[8] = {\n        0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40\n    };\n    RSA *key = RSA_new();\n    const int bits = rsa_security_bits_cases[n].bits;\n    const int result = rsa_security_bits_cases[n].r;\n    const int bytes = (bits + 7) / 8;\n    int r = 0;\n    unsigned char num[2000];\n    if (!TEST_ptr(key) || !TEST_int_le(bytes, (int)sizeof(num)))\n        goto err;\n    memset(num, vals[bits % 8], bytes);\n    if (TEST_true(RSA_set0_key(key, BN_bin2bn(num, bytes, NULL),\n                               BN_bin2bn(num, bytes, NULL), NULL))\n            && TEST_uint_eq(RSA_security_bits(key), result))\n        r = 1;\nerr:\n    RSA_free(key);\n    return r;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return NULL;\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return ret;\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return ret;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}']