crypto/rsa/rsa_sign.c:261: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_malloc()` at line 181, column 9 is not reachable after line 261, column 5.
Showing all 55 steps of the trace


crypto/rsa/rsa_sign.c:158:1: start of procedure int_rsa_verify()
156.   }
157.   
158. > int int_rsa_verify(int dtype, const unsigned char *m,
159.                      unsigned int m_len,
160.                      unsigned char *rm, size_t *prm_len,

crypto/rsa/rsa_sign.c:163:5: 
161.                      const unsigned char *sigbuf, size_t siglen, RSA *rsa)
162.   {
163. >     int i, ret = 0, sigtype;
164.       unsigned char *s;
165.       X509_SIG *sig = NULL;

crypto/rsa/rsa_sign.c:165:5: 
163.       int i, ret = 0, sigtype;
164.       unsigned char *s;
165. >     X509_SIG *sig = NULL;
166.   
167.       if (siglen != (unsigned int)RSA_size(rsa)) {

crypto/rsa/rsa_sign.c:167:9: 
165.       X509_SIG *sig = NULL;
166.   
167. >     if (siglen != (unsigned int)RSA_size(rsa)) {
168.           RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_WRONG_SIGNATURE_LENGTH);
169.           return (0);

crypto/rsa/rsa_crpt.c:71:1: start of procedure RSA_size()
  69.   }
  70.   
  71. > int RSA_size(const RSA *r)
  72.   {
  73.       return (BN_num_bytes(r->n));

crypto/rsa/rsa_crpt.c:73:5: 
  71.   int RSA_size(const RSA *r)
  72.   {
  73. >     return (BN_num_bytes(r->n));
  74.   }
  75.   

crypto/bn/bn_lib.c:214:1: start of procedure BN_num_bits()
    212.   }
    213.   
    214. > int BN_num_bits(const BIGNUM *a)
    215.   {
    216.       int i = a->top - 1;

crypto/bn/bn_lib.c:216:5: 
    214.   int BN_num_bits(const BIGNUM *a)
    215.   {
    216. >     int i = a->top - 1;
    217.       bn_check_top(a);
    218.   

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

crypto/bn/bn_lib.c:975:1: start of procedure BN_is_zero()
      973.   }
      974.   
      975. > int BN_is_zero(const BIGNUM *a)
      976.   {
      977.       return a->top == 0;

crypto/bn/bn_lib.c:977:12: Condition is false
      975.   int BN_is_zero(const BIGNUM *a)
      976.   {
      977.       return a->top == 0;
                        ^
      978.   }
      979.   

crypto/bn/bn_lib.c:977:5: 
      975.   int BN_is_zero(const BIGNUM *a)
      976.   {
      977. >     return a->top == 0;
      978.   }
      979.   

crypto/bn/bn_lib.c:978:1: return from a call to BN_is_zero
      976.   {
      977.       return a->top == 0;
      978. > }
      979.   
      980.   int BN_is_one(const BIGNUM *a)

crypto/bn/bn_lib.c:219:9: Taking false branch
    217.       bn_check_top(a);
    218.   
    219.       if (BN_is_zero(a))
                   ^
    220.           return 0;
    221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

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

crypto/bn/bn_lib.c:222:1: return from a call to BN_num_bits
    220.           return 0;
    221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
    222. > }
    223.   
    224.   static void bn_free_d(BIGNUM *a)

crypto/rsa/rsa_crpt.c:74:1: return from a call to RSA_size
  72.   {
  73.       return (BN_num_bytes(r->n));
  74. > }
  75.   
  76.   int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,

crypto/rsa/rsa_sign.c:167:9: Taking false branch
165.       X509_SIG *sig = NULL;
166.   
167.       if (siglen != (unsigned int)RSA_size(rsa)) {
               ^
168.           RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_WRONG_SIGNATURE_LENGTH);
169.           return (0);

crypto/rsa/rsa_sign.c:172:10: Taking true branch
170.       }
171.   
172.       if ((dtype == NID_md5_sha1) && rm) {
                ^
173.           i = RSA_public_decrypt((int)siglen,
174.                                  sigbuf, rm, rsa, RSA_PKCS1_PADDING);

crypto/rsa/rsa_sign.c:172:36: Taking false branch
170.       }
171.   
172.       if ((dtype == NID_md5_sha1) && rm) {
                                          ^
173.           i = RSA_public_decrypt((int)siglen,
174.                                  sigbuf, rm, rsa, RSA_PKCS1_PADDING);

crypto/rsa/rsa_sign.c:181:5: 
179.       }
180.   
181. >     s = OPENSSL_malloc((unsigned int)siglen);
182.       if (s == NULL) {
183.           RSAerr(RSA_F_INT_RSA_VERIFY, ERR_R_MALLOC_FAILURE);

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
  117.   }
  118.   
  119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
  120.   {
  121.       void *ret = NULL;

crypto/mem.c:121:5: 
  119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
  120.   {
  121. >     void *ret = NULL;
  122.   
  123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:123:9: Taking false branch
  121.       void *ret = NULL;
  122.   
  123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                 ^
  124.           return malloc_impl(num, file, line);
  125.   

crypto/mem.c:126:9: Taking false branch
  124.           return malloc_impl(num, file, line);
  125.   
  126.       if (num <= 0)
                 ^
  127.           return NULL;
  128.   

crypto/mem.c:129:5: 
  127.           return NULL;
  128.   
  129. >     allow_customize = 0;
  130.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  131.       if (call_malloc_debug) {

crypto/mem.c:139:5: 
  137.       }
  138.   #else
  139. >     osslargused(file); osslargused(line);
  140.       ret = malloc(num);
  141.   #endif

crypto/mem.c:139:24: 
  137.       }
  138.   #else
  139. >     osslargused(file); osslargused(line);
  140.       ret = malloc(num);
  141.   #endif

crypto/mem.c:140:5: 
  138.   #else
  139.       osslargused(file); osslargused(line);
  140. >     ret = malloc(num);
  141.   #endif
  142.   

crypto/mem.c:143:5: 
  141.   #endif
  142.   
  143. >     return ret;
  144.   }
  145.   

crypto/mem.c:144:1: return from a call to CRYPTO_malloc
  142.   
  143.       return ret;
  144. > }
  145.   
  146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/rsa/rsa_sign.c:182:9: Taking false branch
180.   
181.       s = OPENSSL_malloc((unsigned int)siglen);
182.       if (s == NULL) {
               ^
183.           RSAerr(RSA_F_INT_RSA_VERIFY, ERR_R_MALLOC_FAILURE);
184.           goto err;

crypto/rsa/rsa_sign.c:186:10: Taking true branch
184.           goto err;
185.       }
186.       if ((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH)) {
                ^
187.           RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_MESSAGE_LENGTH);
188.           goto err;

crypto/rsa/rsa_sign.c:186:37: Taking true branch
184.           goto err;
185.       }
186.       if ((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH)) {
                                           ^
187.           RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_MESSAGE_LENGTH);
188.           goto err;

crypto/rsa/rsa_sign.c:187:9: Skipping ERR_put_error(): empty list of specs
185.       }
186.       if ((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH)) {
187.           RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_MESSAGE_LENGTH);
               ^
188.           goto err;
189.       }

crypto/rsa/rsa_sign.c:259:2: 
257.               ret = 1;
258.       }
259. >  err:
260.       X509_SIG_free(sig);
261.       OPENSSL_clear_free(s, (unsigned int)siglen);

crypto/rsa/rsa_sign.c:260:5: 
258.       }
259.    err:
260. >     X509_SIG_free(sig);
261.       OPENSSL_clear_free(s, (unsigned int)siglen);
262.       return (ret);

crypto/asn1/x_sig.c:69:1: start of procedure X509_SIG_free()
  67.   } ASN1_SEQUENCE_END(X509_SIG)
  68.   
  69. > IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
  70.   
  71.   void X509_SIG_get0(X509_ALGOR **palg, ASN1_OCTET_STRING **pdigest,

crypto/asn1/tasn_fre.c:70:1: start of procedure ASN1_item_free()
    68.   /* Free up an ASN1 structure */
    69.   
    70. > void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
    71.   {
    72.       asn1_item_embed_free(&val, it, 0);

crypto/asn1/tasn_fre.c:72:5: Skipping asn1_item_embed_free(): empty list of specs
    70.   void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
    71.   {
    72.       asn1_item_embed_free(&val, it, 0);
              ^
    73.   }
    74.   

crypto/asn1/tasn_fre.c:73:1: return from a call to ASN1_item_free
    71.   {
    72.       asn1_item_embed_free(&val, it, 0);
    73. > }
    74.   
    75.   void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)

crypto/asn1/x_sig.c:69:1: return from a call to X509_SIG_free
  67.   } ASN1_SEQUENCE_END(X509_SIG)
  68.   
  69. > IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
  70.   
  71.   void X509_SIG_get0(X509_ALGOR **palg, ASN1_OCTET_STRING **pdigest,

crypto/rsa/rsa_sign.c:261:5: 
259.    err:
260.       X509_SIG_free(sig);
261. >     OPENSSL_clear_free(s, (unsigned int)siglen);
262.       return (ret);
263.   }

crypto/mem.c:230:1: start of procedure CRYPTO_clear_free()
  228.   }
  229.   
  230. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  231.   {
  232.       if (str == NULL)

crypto/mem.c:232:9: Taking false branch
  230.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  231.   {
  232.       if (str == NULL)
                 ^
  233.           return;
  234.       if (num)

crypto/mem.c:234:9: Taking true branch
  232.       if (str == NULL)
  233.           return;
  234.       if (num)
                 ^
  235.           OPENSSL_cleanse(str, num);
  236.       CRYPTO_free(str, file, line);

crypto/mem.c:235:9: Skipping OPENSSL_cleanse(): method has no implementation
  233.           return;
  234.       if (num)
  235.           OPENSSL_cleanse(str, num);
                 ^
  236.       CRYPTO_free(str, file, line);
  237.   }

crypto/mem.c:236:5: 
  234.       if (num)
  235.           OPENSSL_cleanse(str, num);
  236. >     CRYPTO_free(str, file, line);
  237.   }

crypto/mem.c:210:1: start of procedure CRYPTO_free()
    208.   }
    209.   
    210. > void CRYPTO_free(void *str, const char *file, int line)
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:212:9: Taking true branch
    210.   void CRYPTO_free(void *str, const char *file, int line)
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    213.           free_impl(str, file, line);
    214.           return;

crypto/mem.c:212:30: Taking true branch
    210.   void CRYPTO_free(void *str, const char *file, int line)
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    213.           free_impl(str, file, line);
    214.           return;

crypto/mem.c:213:9: Skipping __function_pointer__(): unresolved function pointer
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    213.           free_impl(str, file, line);
                   ^
    214.           return;
    215.       }

crypto/mem.c:214:9: 
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    213.           free_impl(str, file, line);
    214. >         return;
    215.       }
    216.   

crypto/mem.c:228:1: return from a call to CRYPTO_free
    226.       free(str);
    227.   #endif
    228. > }
    229.   
    230.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/mem.c:237:1: return from a call to CRYPTO_clear_free
  235.           OPENSSL_cleanse(str, num);
  236.       CRYPTO_free(str, file, line);
  237. > }

int int_rsa_verify(int dtype, const unsigned char *m,
                   unsigned int m_len,
                   unsigned char *rm, size_t *prm_len,
                   const unsigned char *sigbuf, size_t siglen, RSA *rsa)
{
    int i, ret = 0, sigtype;
    unsigned char *s;
    X509_SIG *sig = NULL;
    if (siglen != (unsigned int)RSA_size(rsa)) {
        RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_WRONG_SIGNATURE_LENGTH);
        return (0);
    }
    if ((dtype == NID_md5_sha1) && rm) {
        i = RSA_public_decrypt((int)siglen,
                               sigbuf, rm, rsa, RSA_PKCS1_PADDING);
        if (i <= 0)
            return 0;
        *prm_len = i;
        return 1;
    }
    s = OPENSSL_malloc((unsigned int)siglen);
    if (s == NULL) {
        RSAerr(RSA_F_INT_RSA_VERIFY, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    if ((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH)) {
        RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_MESSAGE_LENGTH);
        goto err;
    }
    i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING);
    if (i <= 0)
        goto err;
    if (dtype == NID_mdc2 && i == 18 && s[0] == 0x04 && s[1] == 0x10) {
        if (rm) {
            memcpy(rm, s + 2, 16);
            *prm_len = 16;
            ret = 1;
        } else if (memcmp(m, s + 2, 16)) {
            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);
        } else {
            ret = 1;
        }
    } else if (dtype == NID_md5_sha1) {
        if ((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);
        else
            ret = 1;
    } else {
        const unsigned char *p = s;
        sig = d2i_X509_SIG(NULL, &p, (long)i);
        if (sig == NULL)
            goto err;
        if (p != s + i || !rsa_check_digestinfo(sig, s, i)) {
            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);
            goto err;
        }
        if (sig->algor->parameter
            && ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL) {
            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);
            goto err;
        }
        sigtype = OBJ_obj2nid(sig->algor->algorithm);
        if (sigtype != dtype) {
            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_ALGORITHM_MISMATCH);
            goto err;
        }
        if (rm) {
            const EVP_MD *md;
            md = EVP_get_digestbynid(dtype);
            if (md && (EVP_MD_size(md) != sig->digest->length))
                RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_DIGEST_LENGTH);
            else {
                memcpy(rm, sig->digest->data, sig->digest->length);
                *prm_len = sig->digest->length;
                ret = 1;
            }
        } else if (((unsigned int)sig->digest->length != m_len) ||
                   (memcmp(m, sig->digest->data, m_len) != 0)) {
            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);
        } else
            ret = 1;
    }
 err:
    X509_SIG_free(sig);
    OPENSSL_clear_free(s, (unsigned int)siglen);
    return (ret);
}
['int int_rsa_verify(int dtype, const unsigned char *m,\n                   unsigned int m_len,\n                   unsigned char *rm, size_t *prm_len,\n                   const unsigned char *sigbuf, size_t siglen, RSA *rsa)\n{\n    int i, ret = 0, sigtype;\n    unsigned char *s;\n    X509_SIG *sig = NULL;\n    if (siglen != (unsigned int)RSA_size(rsa)) {\n        RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_WRONG_SIGNATURE_LENGTH);\n        return (0);\n    }\n    if ((dtype == NID_md5_sha1) && rm) {\n        i = RSA_public_decrypt((int)siglen,\n                               sigbuf, rm, rsa, RSA_PKCS1_PADDING);\n        if (i <= 0)\n            return 0;\n        *prm_len = i;\n        return 1;\n    }\n    s = OPENSSL_malloc((unsigned int)siglen);\n    if (s == NULL) {\n        RSAerr(RSA_F_INT_RSA_VERIFY, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if ((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH)) {\n        RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_MESSAGE_LENGTH);\n        goto err;\n    }\n    i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING);\n    if (i <= 0)\n        goto err;\n    if (dtype == NID_mdc2 && i == 18 && s[0] == 0x04 && s[1] == 0x10) {\n        if (rm) {\n            memcpy(rm, s + 2, 16);\n            *prm_len = 16;\n            ret = 1;\n        } else if (memcmp(m, s + 2, 16)) {\n            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);\n        } else {\n            ret = 1;\n        }\n    } else if (dtype == NID_md5_sha1) {\n        if ((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))\n            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);\n        else\n            ret = 1;\n    } else {\n        const unsigned char *p = s;\n        sig = d2i_X509_SIG(NULL, &p, (long)i);\n        if (sig == NULL)\n            goto err;\n        if (p != s + i || !rsa_check_digestinfo(sig, s, i)) {\n            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);\n            goto err;\n        }\n        if (sig->algor->parameter\n            && ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL) {\n            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);\n            goto err;\n        }\n        sigtype = OBJ_obj2nid(sig->algor->algorithm);\n        if (sigtype != dtype) {\n            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_ALGORITHM_MISMATCH);\n            goto err;\n        }\n        if (rm) {\n            const EVP_MD *md;\n            md = EVP_get_digestbynid(dtype);\n            if (md && (EVP_MD_size(md) != sig->digest->length))\n                RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_DIGEST_LENGTH);\n            else {\n                memcpy(rm, sig->digest->data, sig->digest->length);\n                *prm_len = sig->digest->length;\n                ret = 1;\n            }\n        } else if (((unsigned int)sig->digest->length != m_len) ||\n                   (memcmp(m, sig->digest->data, m_len) != 0)) {\n            RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE);\n        } else\n            ret = 1;\n    }\n err:\n    X509_SIG_free(sig);\n    OPENSSL_clear_free(s, (unsigned int)siglen);\n    return (ret);\n}', 'int RSA_size(const RSA *r)\n{\n    return (BN_num_bytes(r->n));\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}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\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    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}', 'IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)', 'void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)\n{\n    asn1_item_embed_free(&val, it, 0);\n}', 'void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return;\n    if (num)\n        OPENSSL_cleanse(str, num);\n    CRYPTO_free(str, file, line);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}']