crypto/rsa/rsa_ossl.c:199: error: BUFFER_OVERRUN_L3
  Offset added: [10, +oo] (⇐ [2, +oo] + 8) Size: [8, +oo] by call to `RSA_padding_add_SSLv23`.
Showing all 13 steps of the trace


crypto/rsa/rsa_ossl.c:184:11: Call
182.       f = BN_CTX_get(ctx);
183.       ret = BN_CTX_get(ctx);
184.       num = BN_num_bytes(rsa->n);
                 ^
185.       buf = OPENSSL_malloc(num);
186.       if (f == NULL || ret == NULL || buf == NULL) {

crypto/bn/bn_lib.c:221:9: Assignment
  219.   
  220.       if (BN_is_zero(a))
  221.           return 0;
                 ^
  222.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
  223.   }

crypto/rsa/rsa_ossl.c:184:5: Assignment
182.       f = BN_CTX_get(ctx);
183.       ret = BN_CTX_get(ctx);
184.       num = BN_num_bytes(rsa->n);
           ^
185.       buf = OPENSSL_malloc(num);
186.       if (f == NULL || ret == NULL || buf == NULL) {

crypto/rsa/rsa_ossl.c:185:11: Call
183.       ret = BN_CTX_get(ctx);
184.       num = BN_num_bytes(rsa->n);
185.       buf = OPENSSL_malloc(num);
                 ^
186.       if (f == NULL || ret == NULL || buf == NULL) {
187.           RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);

crypto/mem.c:125:9: Assignment
  123.   
  124.       if (num <= 0)
  125.           return NULL;
                 ^
  126.   
  127.       allow_customize = 0;

crypto/rsa/rsa_ossl.c:185:5: Assignment
183.       ret = BN_CTX_get(ctx);
184.       num = BN_num_bytes(rsa->n);
185.       buf = OPENSSL_malloc(num);
           ^
186.       if (f == NULL || ret == NULL || buf == NULL) {
187.           RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);

crypto/rsa/rsa_ossl.c:199:13: Call
197.           break;
198.       case RSA_SSLV23_PADDING:
199.           i = RSA_padding_add_SSLv23(buf, num, from, flen);
                   ^
200.           break;
201.       case RSA_NO_PADDING:

crypto/rsa/rsa_ssl.c:65:1: <Length trace>
63.   #include <openssl/rand.h>
64.   
65. > int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
66.                              const unsigned char *from, int flen)
67.   {

crypto/rsa/rsa_ssl.c:65:1: Parameter `*to`
  63.   #include <openssl/rand.h>
  64.   
  65. > int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
  66.                              const unsigned char *from, int flen)
  67.   {

crypto/rsa/rsa_ssl.c:77:5: Assignment
  75.       }
  76.   
  77.       p = (unsigned char *)to;
            ^
  78.   
  79.       *(p++) = 0;

crypto/rsa/rsa_ssl.c:79:7: Assignment
  77.       p = (unsigned char *)to;
  78.   
  79.       *(p++) = 0;
              ^
  80.       *(p++) = 2;                 /* Public Key BT (Block Type) */
  81.   

crypto/rsa/rsa_ssl.c:80:7: Assignment
  78.   
  79.       *(p++) = 0;
  80.       *(p++) = 2;                 /* Public Key BT (Block Type) */
              ^
  81.   
  82.       /* pad out with non-zero random data */

crypto/rsa/rsa_ssl.c:96:5: Array access: Offset added: [10, +oo] (⇐ [2, +oo] + 8) Size: [8, +oo] by call to `RSA_padding_add_SSLv23` 
  94.       }
  95.   
  96.       memset(p, 3, 8);
            ^
  97.       p += 8;
  98.       *(p++) = '\0';

int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
                           const unsigned char *from, int flen)
{
    int i, j;
    unsigned char *p;
    if (flen > (tlen - 11)) {
        RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,
               RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
        return (0);
    }
    p = (unsigned char *)to;
    *(p++) = 0;
    *(p++) = 2;
    j = tlen - 3 - 8 - flen;
    if (RAND_bytes(p, j) <= 0)
        return (0);
    for (i = 0; i < j; i++) {
        if (*p == '\0')
            do {
                if (RAND_bytes(p, 1) <= 0)
                    return (0);
            } while (*p == '\0');
        p++;
    }
    memset(p, 3, 8);
    p += 8;
    *(p++) = '\0';
    memcpy(p, from, (unsigned int)flen);
    return (1);
}
['static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,\n                                  unsigned char *to, RSA *rsa, int padding)\n{\n    BIGNUM *f, *ret;\n    int i, j, k, num = 0, r = -1;\n    unsigned char *buf = NULL;\n    BN_CTX *ctx = NULL;\n    if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);\n        return -1;\n    }\n    if (BN_ucmp(rsa->n, rsa->e) <= 0) {\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n        return -1;\n    }\n    if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {\n        if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {\n            RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n            return -1;\n        }\n    }\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_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    switch (padding) {\n    case RSA_PKCS1_PADDING:\n        i = RSA_padding_add_PKCS1_type_2(buf, num, from, flen);\n        break;\n    case RSA_PKCS1_OAEP_PADDING:\n        i = RSA_padding_add_PKCS1_OAEP(buf, num, from, flen, NULL, 0);\n        break;\n    case RSA_SSLV23_PADDING:\n        i = RSA_padding_add_SSLv23(buf, num, from, flen);\n        break;\n    case RSA_NO_PADDING:\n        i = RSA_padding_add_none(buf, num, from, flen);\n        break;\n    default:\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n        goto err;\n    }\n    if (i <= 0)\n        goto err;\n    if (BN_bin2bn(buf, num, f) == NULL)\n        goto err;\n    if (BN_ucmp(f, rsa->n) >= 0) {\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT,\n               RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n        goto err;\n    }\n    if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n        if (!BN_MONT_CTX_set_locked\n            (&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))\n            goto err;\n    if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,\n                               rsa->_method_mod_n))\n        goto err;\n    j = BN_num_bytes(ret);\n    i = BN_bn2bin(ret, &(to[num - j]));\n    for (k = 0; k < (num - i); k++)\n        to[k] = 0;\n    r = num;\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}', 'int BN_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifdef 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    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', "int RSA_padding_add_SSLv23(unsigned char *to, int tlen,\n                           const unsigned char *from, int flen)\n{\n    int i, j;\n    unsigned char *p;\n    if (flen > (tlen - 11)) {\n        RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,\n               RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);\n        return (0);\n    }\n    p = (unsigned char *)to;\n    *(p++) = 0;\n    *(p++) = 2;\n    j = tlen - 3 - 8 - flen;\n    if (RAND_bytes(p, j) <= 0)\n        return (0);\n    for (i = 0; i < j; i++) {\n        if (*p == '\\0')\n            do {\n                if (RAND_bytes(p, 1) <= 0)\n                    return (0);\n            } while (*p == '\\0');\n        p++;\n    }\n    memset(p, 3, 8);\n    p += 8;\n    *(p++) = '\\0';\n    memcpy(p, from, (unsigned int)flen);\n    return (1);\n}"]