crypto/rsa/rsa_ossl.c:418: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `rsa_blinding_convert`.
Showing all 25 steps of the trace


crypto/rsa/rsa_ossl.c:396:9: Call
394.   
395.       /* make data into a big number */
396.       if (BN_bin2bn(from, (int)flen, f) == NULL)
               ^
397.           goto err;
398.   

crypto/bn/bn_lib.c:407:1: Parameter `ret->top`
  405.   }
  406.   
  407. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  408.   {
  409.       unsigned int i, m;

crypto/rsa/rsa_ossl.c:418:14: Call
416.               goto err;
417.           }
418.           if (!rsa_blinding_convert(blinding, f, unblind, ctx))
                    ^
419.               goto err;
420.       }

crypto/rsa/rsa_ossl.c:185:1: Parameter `unblind->top`
  183.   }
  184.   
  185. > static int rsa_blinding_convert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,
  186.                                   BN_CTX *ctx)
  187.   {

crypto/rsa/rsa_ossl.c:200:15: Call
  198.   
  199.           BN_BLINDING_lock(b);
  200.           ret = BN_BLINDING_convert_ex(f, unblind, b, ctx);
                       ^
  201.           BN_BLINDING_unlock(b);
  202.   

crypto/bn/bn_blind.c:130:1: Parameter `r->top`
    128.   }
    129.   
    130. > int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
    131.   {
    132.       int ret = 1;

crypto/bn/bn_blind.c:148:14: Call
    146.   
    147.       if (r != NULL) {
    148.           if (!BN_copy(r, b->Ai))
                        ^
    149.               ret = 0;
    150.       }

crypto/bn/bn_lib.c:323:1: Parameter `a->top`
      321.   }
      322.   
      323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      324.   {
      325.       bn_check_top(b);

crypto/bn/bn_lib.c:329:9: Call
      327.       if (a == b)
      328.           return a;
      329.       if (bn_wexpand(a, b->top) == NULL)
                     ^
      330.           return NULL;
      331.   

crypto/bn/bn_lib.c:948:1: Parameter `a->top`
        946.   }
        947.   
        948. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
        949.   {
        950.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:950:37: Call
        948.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
        949.   {
        950.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                   ^
        951.   }
        952.   

crypto/bn/bn_lib.c:284:1: Parameter `b->top`
          282.    */
          283.   
          284. > BIGNUM *bn_expand2(BIGNUM *b, int words)
          285.   {
          286.       bn_check_top(b);

crypto/bn/bn_lib.c:289:23: Call
          287.   
          288.       if (words > b->dmax) {
          289.           BN_ULONG *a = bn_expand_internal(b, words);
                                       ^
          290.           if (!a)
          291.               return NULL;

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

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

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

crypto/bn/bn_lib.c:246:1: Parameter `words`
            244.   /* This is used by bn_expand2() */
            245.   /* The caller MUST check that words > b->dmax before calling this */
            246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
            247.   {
            248.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:263:13: Call
            261.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
            262.       else
            263.           a = OPENSSL_zalloc(words * sizeof(*a));
                               ^
            264.       if (a == NULL) {
            265.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:186:1: Parameter `num`
              184.   }
              185.   
              186. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
              187.   {
              188.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:188:17: Call
              186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
              187.   {
              188.       void *ret = CRYPTO_malloc(num, file, line);
                                     ^
              189.   
              190.       FAILTEST();

crypto/mem.c:166:9: Assignment
                164.   
                165.       if (num == 0)
                166.           return NULL;
                               ^
                167.   
                168.       FAILTEST();

crypto/mem.c:188:5: Assignment
              186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
              187.   {
              188.       void *ret = CRYPTO_malloc(num, file, line);
                         ^
              189.   
              190.       FAILTEST();

crypto/mem.c:193:5: Assignment
              191.       if (ret != NULL)
              192.           memset(ret, 0, num);
              193.       return ret;
                         ^
              194.   }
              195.   

crypto/bn/bn_lib.c:263:9: Assignment
            261.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
            262.       else
            263.           a = OPENSSL_zalloc(words * sizeof(*a));
                           ^
            264.       if (a == NULL) {
            265.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:271:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `rsa_blinding_convert` 
            269.       assert(b->top <= words);
            270.       if (b->top > 0)
            271.           memcpy(a, b->d, sizeof(*a) * b->top);
                           ^
            272.   
            273.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    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 rsa_ossl_private_decrypt(int flen, const unsigned char *from,\n                                   unsigned char *to, RSA *rsa, int padding)\n{\n    BIGNUM *f, *ret;\n    int j, num = 0, r = -1;\n    unsigned char *p;\n    unsigned char *buf = NULL;\n    BN_CTX *ctx = NULL;\n    int local_blinding = 0;\n    BIGNUM *unblind = NULL;\n    BN_BLINDING *blinding = NULL;\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    f = BN_CTX_get(ctx);\n    ret = BN_CTX_get(ctx);\n    num = BN_num_bytes(rsa->n);\n    buf = OPENSSL_malloc(num);\n    if (f == NULL || ret == NULL || buf == NULL) {\n        RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (flen > num) {\n        RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT,\n               RSA_R_DATA_GREATER_THAN_MOD_LEN);\n        goto err;\n    }\n    if (BN_bin2bn(from, (int)flen, f) == NULL)\n        goto err;\n    if (BN_ucmp(f, rsa->n) >= 0) {\n        RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT,\n               RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n        goto err;\n    }\n    if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {\n        blinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n        if (blinding == NULL) {\n            RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);\n            goto err;\n        }\n    }\n    if (blinding != NULL) {\n        if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {\n            RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if (!rsa_blinding_convert(blinding, f, unblind, ctx))\n            goto err;\n    }\n    if ((rsa->flags & RSA_FLAG_EXT_PKEY) ||\n        ((rsa->p != NULL) &&\n         (rsa->q != NULL) &&\n         (rsa->dmp1 != NULL) && (rsa->dmq1 != NULL) && (rsa->iqmp != NULL))) {\n        if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx))\n            goto err;\n    } else {\n        BIGNUM *d = BN_new();\n        if (d == NULL) {\n            RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n        if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n            if (!BN_MONT_CTX_set_locked\n                (&rsa->_method_mod_n, rsa->lock, rsa->n, ctx)) {\n                BN_free(d);\n                goto err;\n            }\n        if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,\n                                   rsa->_method_mod_n)) {\n            BN_free(d);\n            goto err;\n        }\n        BN_free(d);\n    }\n    if (blinding)\n        if (!rsa_blinding_invert(blinding, ret, unblind, ctx))\n            goto err;\n    p = buf;\n    j = BN_bn2bin(ret, p);\n    switch (padding) {\n    case RSA_PKCS1_PADDING:\n        r = RSA_padding_check_PKCS1_type_2(to, num, buf, j, num);\n        break;\n    case RSA_PKCS1_OAEP_PADDING:\n        r = RSA_padding_check_PKCS1_OAEP(to, num, buf, j, num, NULL, 0);\n        break;\n    case RSA_SSLV23_PADDING:\n        r = RSA_padding_check_SSLv23(to, num, buf, j, num);\n        break;\n    case RSA_NO_PADDING:\n        r = RSA_padding_check_none(to, num, buf, j, num);\n        break;\n    default:\n        RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n        goto err;\n    }\n    if (r < 0)\n        RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);\n err:\n    if (ctx != NULL)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    OPENSSL_clear_free(buf, num);\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}', 'static int rsa_blinding_convert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,\n                                BN_CTX *ctx)\n{\n    if (unblind == NULL)\n        return BN_BLINDING_convert_ex(f, NULL, b, ctx);\n    else {\n        int ret;\n        BN_BLINDING_lock(b);\n        ret = BN_BLINDING_convert_ex(f, unblind, b, ctx);\n        BN_BLINDING_unlock(b);\n        return ret;\n    }\n}', 'int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)\n{\n    int ret = 1;\n    bn_check_top(n);\n    if ((b->A == NULL) || (b->Ai == NULL)) {\n        BNerr(BN_F_BN_BLINDING_CONVERT_EX, BN_R_NOT_INITIALIZED);\n        return (0);\n    }\n    if (b->counter == -1)\n        b->counter = 0;\n    else if (!BN_BLINDING_update(b, ctx))\n        return (0);\n    if (r != NULL) {\n        if (!BN_copy(r, b->Ai))\n            ret = 0;\n    }\n    if (!BN_mod_mul(n, n, b->A, b->mod, ctx))\n        ret = 0;\n    return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\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    bn_check_top(b);\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    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\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}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']