crypto/rsa/rsa_ossl.c:693: error: BUFFER_OVERRUN_L3
  Offset: [1, 2] Size: [1, +oo] by call to `RSA_padding_check_PKCS1_type_1`.
Showing all 12 steps of the trace


crypto/rsa/rsa_ossl.c:650:11: Call
648.       f = BN_CTX_get(ctx);
649.       ret = BN_CTX_get(ctx);
650.       num = BN_num_bytes(rsa->n);
                 ^
651.       buf = OPENSSL_malloc(num);
652.       if (f == NULL || ret == NULL || buf == NULL) {

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

crypto/rsa/rsa_ossl.c:650:5: Assignment
648.       f = BN_CTX_get(ctx);
649.       ret = BN_CTX_get(ctx);
650.       num = BN_num_bytes(rsa->n);
           ^
651.       buf = OPENSSL_malloc(num);
652.       if (f == NULL || ret == NULL || buf == NULL) {

crypto/rsa/rsa_ossl.c:651:11: Call
649.       ret = BN_CTX_get(ctx);
650.       num = BN_num_bytes(rsa->n);
651.       buf = OPENSSL_malloc(num);
                 ^
652.       if (f == NULL || ret == NULL || buf == NULL) {
653.           RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE);

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

crypto/rsa/rsa_ossl.c:651:5: Assignment
649.       ret = BN_CTX_get(ctx);
650.       num = BN_num_bytes(rsa->n);
651.       buf = OPENSSL_malloc(num);
           ^
652.       if (f == NULL || ret == NULL || buf == NULL) {
653.           RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE);

crypto/rsa/rsa_ossl.c:693:13: Call
691.       switch (padding) {
692.       case RSA_PKCS1_PADDING:
693.           r = RSA_padding_check_PKCS1_type_1(to, num, buf, i, num);
                   ^
694.           break;
695.       case RSA_X931_PADDING:

crypto/rsa/rsa_pk1.c:92:1: <Length trace>
90.   }
91.   
92. > int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
93.                                      const unsigned char *from, int flen,
94.                                      int num)

crypto/rsa/rsa_pk1.c:92:1: Parameter `*from`
  90.   }
  91.   
  92. > int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
  93.                                      const unsigned char *from, int flen,
  94.                                      int num)

crypto/rsa/rsa_pk1.c:99:5: Assignment
  97.       const unsigned char *p;
  98.   
  99.       p = from;
             ^
  100.   
  101.       /*

crypto/rsa/rsa_pk1.c:121:35: Assignment
  119.       }
  120.   
  121.       if ((num != (flen + 1)) || (*(p++) != 0x01)) {
                                           ^
  122.           RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
  123.                  RSA_R_BLOCK_TYPE_IS_NOT_01);

crypto/rsa/rsa_pk1.c:131:17: Array access: Offset: [1, 2] Size: [1, +oo] by call to `RSA_padding_check_PKCS1_type_1` 
  129.       for (i = 0; i < j; i++) {
  130.           if (*p != 0xff) {       /* should decrypt to 0xff */
  131.               if (*p == 0) {
                         ^
  132.                   p++;
  133.                   break;

int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
                                   const unsigned char *from, int flen,
                                   int num)
{
    int i, j;
    const unsigned char *p;
    p = from;
    if (num < 11)
        return -1;
    if (num == flen) {
        if ((*p++) != 0x00) {
            RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
                   RSA_R_INVALID_PADDING);
            return -1;
        }
        flen--;
    }
    if ((num != (flen + 1)) || (*(p++) != 0x01)) {
        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
               RSA_R_BLOCK_TYPE_IS_NOT_01);
        return (-1);
    }
    j = flen - 1;
    for (i = 0; i < j; i++) {
        if (*p != 0xff) {
            if (*p == 0) {
                p++;
                break;
            } else {
                RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
                       RSA_R_BAD_FIXED_HEADER_DECRYPT);
                return (-1);
            }
        }
        p++;
    }
    if (i == j) {
        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
               RSA_R_NULL_BEFORE_BLOCK_MISSING);
        return (-1);
    }
    if (i < 8) {
        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
               RSA_R_BAD_PAD_BYTE_COUNT);
        return (-1);
    }
    i++;
    j -= i;
    if (j > tlen) {
        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_DATA_TOO_LARGE);
        return (-1);
    }
    memcpy(to, p, (unsigned int)j);
    return (j);
}
['static int rsa_ossl_public_decrypt(int flen, const unsigned char *from,\n                                  unsigned char *to, RSA *rsa, int padding)\n{\n    BIGNUM *f, *ret;\n    int i, num = 0, r = -1;\n    unsigned char *p;\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_DECRYPT, 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_DECRYPT, 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_DECRYPT, 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_DECRYPT, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (flen > num) {\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_DATA_GREATER_THAN_MOD_LEN);\n        goto err;\n    }\n    if (BN_bin2bn(from, flen, f) == NULL)\n        goto err;\n    if (BN_ucmp(f, rsa->n) >= 0) {\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT,\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    if ((padding == RSA_X931_PADDING) && ((bn_get_words(ret)[0] & 0xf) != 12))\n        if (!BN_sub(ret, rsa->n, ret))\n            goto err;\n    p = buf;\n    i = BN_bn2bin(ret, p);\n    switch (padding) {\n    case RSA_PKCS1_PADDING:\n        r = RSA_padding_check_PKCS1_type_1(to, num, buf, i, num);\n        break;\n    case RSA_X931_PADDING:\n        r = RSA_padding_check_X931(to, num, buf, i, num);\n        break;\n    case RSA_NO_PADDING:\n        r = RSA_padding_check_none(to, num, buf, i, num);\n        break;\n    default:\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n        goto err;\n    }\n    if (r < 0)\n        RSAerr(RSA_F_RSA_OSSL_PUBLIC_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}', '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#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    (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_check_PKCS1_type_1(unsigned char *to, int tlen,\n                                   const unsigned char *from, int flen,\n                                   int num)\n{\n    int i, j;\n    const unsigned char *p;\n    p = from;\n    if (num < 11)\n        return -1;\n    if (num == flen) {\n        if ((*p++) != 0x00) {\n            RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n                   RSA_R_INVALID_PADDING);\n            return -1;\n        }\n        flen--;\n    }\n    if ((num != (flen + 1)) || (*(p++) != 0x01)) {\n        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n               RSA_R_BLOCK_TYPE_IS_NOT_01);\n        return (-1);\n    }\n    j = flen - 1;\n    for (i = 0; i < j; i++) {\n        if (*p != 0xff) {\n            if (*p == 0) {\n                p++;\n                break;\n            } else {\n                RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n                       RSA_R_BAD_FIXED_HEADER_DECRYPT);\n                return (-1);\n            }\n        }\n        p++;\n    }\n    if (i == j) {\n        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n               RSA_R_NULL_BEFORE_BLOCK_MISSING);\n        return (-1);\n    }\n    if (i < 8) {\n        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n               RSA_R_BAD_PAD_BYTE_COUNT);\n        return (-1);\n    }\n    i++;\n    j -= i;\n    if (j > tlen) {\n        RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_DATA_TOO_LARGE);\n        return (-1);\n    }\n    memcpy(to, p, (unsigned int)j);\n    return (j);\n}']