ssl/t1_lib.c:3100: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_CIPHER_CTX_new()` at line 3003, column 11 is not reachable after line 3100, column 5.
Showing all 37 steps of the trace


ssl/t1_lib.c:2984:1: start of procedure tls_decrypt_ticket()
2982.    *    4: same as 3, but the ticket needs to be renewed.
2983.    */
2984. > static int tls_decrypt_ticket(SSL *s, const unsigned char *etick,
2985.                                 int eticklen, const unsigned char *sess_id,
2986.                                 int sesslen, SSL_SESSION **psess)

ssl/t1_lib.c:2991:5: 
2989.       unsigned char *sdec;
2990.       const unsigned char *p;
2991. >     int slen, mlen, renew_ticket = 0, ret = -1;
2992.       unsigned char tick_hmac[EVP_MAX_MD_SIZE];
2993.       HMAC_CTX *hctx = NULL;

ssl/t1_lib.c:2993:5: 
2991.       int slen, mlen, renew_ticket = 0, ret = -1;
2992.       unsigned char tick_hmac[EVP_MAX_MD_SIZE];
2993. >     HMAC_CTX *hctx = NULL;
2994.       EVP_CIPHER_CTX *ctx;
2995.       SSL_CTX *tctx = s->initial_ctx;

ssl/t1_lib.c:2995:5: 
2993.       HMAC_CTX *hctx = NULL;
2994.       EVP_CIPHER_CTX *ctx;
2995. >     SSL_CTX *tctx = s->initial_ctx;
2996.       /* Need at least keyname + iv + some encrypted data */
2997.       if (eticklen < 48)

ssl/t1_lib.c:2997:9: Taking false branch
2995.       SSL_CTX *tctx = s->initial_ctx;
2996.       /* Need at least keyname + iv + some encrypted data */
2997.       if (eticklen < 48)
                ^
2998.           return 2;
2999.       /* Initialize session ticket encryption and HMAC contexts */

ssl/t1_lib.c:3000:5: Skipping HMAC_CTX_new(): empty list of specs
2998.           return 2;
2999.       /* Initialize session ticket encryption and HMAC contexts */
3000.       hctx = HMAC_CTX_new();
            ^
3001.       if (hctx == NULL)
3002.           return -2;

ssl/t1_lib.c:3001:9: Taking false branch
2999.       /* Initialize session ticket encryption and HMAC contexts */
3000.       hctx = HMAC_CTX_new();
3001.       if (hctx == NULL)
                ^
3002.           return -2;
3003.       ctx = EVP_CIPHER_CTX_new();

ssl/t1_lib.c:3003:5: 
3001.       if (hctx == NULL)
3002.           return -2;
3003. >     ctx = EVP_CIPHER_CTX_new();
3004.       if (ctx == NULL) {
3005.           ret = -2;

crypto/evp/evp_enc.c:38:1: start of procedure EVP_CIPHER_CTX_new()
  36.   }
  37.   
  38. > EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  39.   {
  40.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));

crypto/evp/evp_enc.c:40:5: 
  38.   EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  39.   {
  40. >     return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  41.   }
  42.   

crypto/mem.c:98:1: start of procedure CRYPTO_zalloc()
    96.   }
    97.   
    98. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:100:5: 
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100. >     void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)

crypto/mem.c:71:1: start of procedure CRYPTO_malloc()
      69.   }
      70.   
      71. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73.       void *ret = NULL;

crypto/mem.c:73:5: 
      71.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73. >     void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:75:9: Taking false branch
      73.       void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                    ^
      76.           return malloc_impl(num, file, line);
      77.   

crypto/mem.c:78:9: Taking false branch
      76.           return malloc_impl(num, file, line);
      77.   
      78.       if (num <= 0)
                    ^
      79.           return NULL;
      80.   

crypto/mem.c:81:5: 
      79.           return NULL;
      80.   
      81. >     allow_customize = 0;
      82.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      83.       if (call_malloc_debug) {

crypto/mem.c:91:5: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:91:24: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:92:5: 
      90.   #else
      91.       osslargused(file); osslargused(line);
      92. >     ret = malloc(num);
      93.   #endif
      94.   

crypto/mem.c:95:5: 
      93.   #endif
      94.   
      95. >     return ret;
      96.   }
      97.   

crypto/mem.c:96:1: return from a call to CRYPTO_malloc
      94.   
      95.       return ret;
      96. > }
      97.   
      98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:102:9: Taking true branch
    100.       void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)
                   ^
    103.           memset(ret, 0, num);
    104.       return ret;

crypto/mem.c:103:9: 
    101.   
    102.       if (ret != NULL)
    103. >         memset(ret, 0, num);
    104.       return ret;
    105.   }

crypto/mem.c:104:5: 
    102.       if (ret != NULL)
    103.           memset(ret, 0, num);
    104. >     return ret;
    105.   }
    106.   

crypto/mem.c:105:1: return from a call to CRYPTO_zalloc
    103.           memset(ret, 0, num);
    104.       return ret;
    105. > }
    106.   
    107.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/evp_enc.c:41:1: return from a call to EVP_CIPHER_CTX_new
  39.   {
  40.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  41. > }
  42.   
  43.   void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)

ssl/t1_lib.c:3004:9: Taking false branch
3002.           return -2;
3003.       ctx = EVP_CIPHER_CTX_new();
3004.       if (ctx == NULL) {
                ^
3005.           ret = -2;
3006.           goto err;

ssl/t1_lib.c:3008:9: Taking false branch
3006.           goto err;
3007.       }
3008.       if (tctx->tlsext_ticket_key_cb) {
                ^
3009.           unsigned char *nctick = (unsigned char *)etick;
3010.           int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,

ssl/t1_lib.c:3022:13: Taking false branch
3020.       } else {
3021.           /* Check key name matches */
3022.           if (memcmp(etick, tctx->tlsext_tick_key_name,
                    ^
3023.                      sizeof(tctx->tlsext_tick_key_name)) != 0) {
3024.               ret = 2;

ssl/t1_lib.c:3027:13: 
3025.               goto err;
3026.           }
3027. >         if (HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key,
3028.                            sizeof(tctx->tlsext_tick_hmac_key),
3029.                            EVP_sha256(), NULL) <= 0

crypto/evp/m_sha1.c:166:1: start of procedure EVP_sha256()
  164.   };
  165.   
  166. > const EVP_MD *EVP_sha256(void)
  167.   {
  168.       return (&sha256_md);

crypto/evp/m_sha1.c:168:5: 
  166.   const EVP_MD *EVP_sha256(void)
  167.   {
  168. >     return (&sha256_md);
  169.   }
  170.   

crypto/evp/m_sha1.c:169:1: return from a call to EVP_sha256
  167.   {
  168.       return (&sha256_md);
  169. > }
  170.   
  171.   static int init384(EVP_MD_CTX *ctx)

ssl/t1_lib.c:3027:13: Taking true branch
3025.               goto err;
3026.           }
3027.           if (HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key,
                    ^
3028.                            sizeof(tctx->tlsext_tick_hmac_key),
3029.                            EVP_sha256(), NULL) <= 0

ssl/t1_lib.c:3099:1: 
3097.        */
3098.       return 2;
3099. > err:
3100.       EVP_CIPHER_CTX_free(ctx);
3101.       HMAC_CTX_free(hctx);

ssl/t1_lib.c:3100:5: Skipping EVP_CIPHER_CTX_free(): empty list of specs
3098.       return 2;
3099.   err:
3100.       EVP_CIPHER_CTX_free(ctx);
            ^
3101.       HMAC_CTX_free(hctx);
3102.       return ret;

static int tls_decrypt_ticket(SSL *s, const unsigned char *etick,
                              int eticklen, const unsigned char *sess_id,
                              int sesslen, SSL_SESSION **psess)
{
    SSL_SESSION *sess;
    unsigned char *sdec;
    const unsigned char *p;
    int slen, mlen, renew_ticket = 0, ret = -1;
    unsigned char tick_hmac[EVP_MAX_MD_SIZE];
    HMAC_CTX *hctx = NULL;
    EVP_CIPHER_CTX *ctx;
    SSL_CTX *tctx = s->initial_ctx;
    if (eticklen < 48)
        return 2;
    hctx = HMAC_CTX_new();
    if (hctx == NULL)
        return -2;
    ctx = EVP_CIPHER_CTX_new();
    if (ctx == NULL) {
        ret = -2;
        goto err;
    }
    if (tctx->tlsext_ticket_key_cb) {
        unsigned char *nctick = (unsigned char *)etick;
        int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,
                                            ctx, hctx, 0);
        if (rv < 0)
            goto err;
        if (rv == 0) {
            ret = 2;
            goto err;
        }
        if (rv == 2)
            renew_ticket = 1;
    } else {
        if (memcmp(etick, tctx->tlsext_tick_key_name,
                   sizeof(tctx->tlsext_tick_key_name)) != 0) {
            ret = 2;
            goto err;
        }
        if (HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key,
                         sizeof(tctx->tlsext_tick_hmac_key),
                         EVP_sha256(), NULL) <= 0
                || EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL,
                                      tctx->tlsext_tick_aes_key,
                                      etick + sizeof(tctx->tlsext_tick_key_name)) <= 0) {
            goto err;
       }
    }
    mlen = HMAC_size(hctx);
    if (mlen < 0) {
        goto err;
    }
    eticklen -= mlen;
    if (HMAC_Update(hctx, etick, eticklen) <= 0
            || HMAC_Final(hctx, tick_hmac, NULL) <= 0) {
        goto err;
    }
    HMAC_CTX_free(hctx);
    if (CRYPTO_memcmp(tick_hmac, etick + eticklen, mlen)) {
        EVP_CIPHER_CTX_free(ctx);
        return 2;
    }
    p = etick + 16 + EVP_CIPHER_CTX_iv_length(ctx);
    eticklen -= 16 + EVP_CIPHER_CTX_iv_length(ctx);
    sdec = OPENSSL_malloc(eticklen);
    if (sdec == NULL
            || EVP_DecryptUpdate(ctx, sdec, &slen, p, eticklen) <= 0) {
        EVP_CIPHER_CTX_free(ctx);
        OPENSSL_free(sdec);
        return -1;
    }
    if (EVP_DecryptFinal(ctx, sdec + slen, &mlen) <= 0) {
        EVP_CIPHER_CTX_free(ctx);
        OPENSSL_free(sdec);
        return 2;
    }
    slen += mlen;
    EVP_CIPHER_CTX_free(ctx);
    ctx = NULL;
    p = sdec;
    sess = d2i_SSL_SESSION(NULL, &p, slen);
    OPENSSL_free(sdec);
    if (sess) {
        if (sesslen)
            memcpy(sess->session_id, sess_id, sesslen);
        sess->session_id_length = sesslen;
        *psess = sess;
        if (renew_ticket)
            return 4;
        else
            return 3;
    }
    ERR_clear_error();
    return 2;
err:
    EVP_CIPHER_CTX_free(ctx);
    HMAC_CTX_free(hctx);
    return ret;
}
['static int tls_decrypt_ticket(SSL *s, const unsigned char *etick,\n                              int eticklen, const unsigned char *sess_id,\n                              int sesslen, SSL_SESSION **psess)\n{\n    SSL_SESSION *sess;\n    unsigned char *sdec;\n    const unsigned char *p;\n    int slen, mlen, renew_ticket = 0, ret = -1;\n    unsigned char tick_hmac[EVP_MAX_MD_SIZE];\n    HMAC_CTX *hctx = NULL;\n    EVP_CIPHER_CTX *ctx;\n    SSL_CTX *tctx = s->initial_ctx;\n    if (eticklen < 48)\n        return 2;\n    hctx = HMAC_CTX_new();\n    if (hctx == NULL)\n        return -2;\n    ctx = EVP_CIPHER_CTX_new();\n    if (ctx == NULL) {\n        ret = -2;\n        goto err;\n    }\n    if (tctx->tlsext_ticket_key_cb) {\n        unsigned char *nctick = (unsigned char *)etick;\n        int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,\n                                            ctx, hctx, 0);\n        if (rv < 0)\n            goto err;\n        if (rv == 0) {\n            ret = 2;\n            goto err;\n        }\n        if (rv == 2)\n            renew_ticket = 1;\n    } else {\n        if (memcmp(etick, tctx->tlsext_tick_key_name,\n                   sizeof(tctx->tlsext_tick_key_name)) != 0) {\n            ret = 2;\n            goto err;\n        }\n        if (HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key,\n                         sizeof(tctx->tlsext_tick_hmac_key),\n                         EVP_sha256(), NULL) <= 0\n                || EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL,\n                                      tctx->tlsext_tick_aes_key,\n                                      etick + sizeof(tctx->tlsext_tick_key_name)) <= 0) {\n            goto err;\n       }\n    }\n    mlen = HMAC_size(hctx);\n    if (mlen < 0) {\n        goto err;\n    }\n    eticklen -= mlen;\n    if (HMAC_Update(hctx, etick, eticklen) <= 0\n            || HMAC_Final(hctx, tick_hmac, NULL) <= 0) {\n        goto err;\n    }\n    HMAC_CTX_free(hctx);\n    if (CRYPTO_memcmp(tick_hmac, etick + eticklen, mlen)) {\n        EVP_CIPHER_CTX_free(ctx);\n        return 2;\n    }\n    p = etick + 16 + EVP_CIPHER_CTX_iv_length(ctx);\n    eticklen -= 16 + EVP_CIPHER_CTX_iv_length(ctx);\n    sdec = OPENSSL_malloc(eticklen);\n    if (sdec == NULL\n            || EVP_DecryptUpdate(ctx, sdec, &slen, p, eticklen) <= 0) {\n        EVP_CIPHER_CTX_free(ctx);\n        OPENSSL_free(sdec);\n        return -1;\n    }\n    if (EVP_DecryptFinal(ctx, sdec + slen, &mlen) <= 0) {\n        EVP_CIPHER_CTX_free(ctx);\n        OPENSSL_free(sdec);\n        return 2;\n    }\n    slen += mlen;\n    EVP_CIPHER_CTX_free(ctx);\n    ctx = NULL;\n    p = sdec;\n    sess = d2i_SSL_SESSION(NULL, &p, slen);\n    OPENSSL_free(sdec);\n    if (sess) {\n        if (sesslen)\n            memcpy(sess->session_id, sess_id, sesslen);\n        sess->session_id_length = sesslen;\n        *psess = sess;\n        if (renew_ticket)\n            return 4;\n        else\n            return 3;\n    }\n    ERR_clear_error();\n    return 2;\nerr:\n    EVP_CIPHER_CTX_free(ctx);\n    HMAC_CTX_free(hctx);\n    return ret;\n}', 'EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\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    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}', 'const EVP_MD *EVP_sha256(void)\n{\n    return (&sha256_md);\n}']