ssl/t1_lib.c:3080: error: MEMORY_LEAK
  memory dynamically allocated to `return` by call to `HMAC_CTX_new()` at line 3069, column 12 is not reachable after line 3080, column 13.
Showing all 53 steps of the trace


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

ssl/t1_lib.c:3060:5: 
3058.       unsigned char *sdec;
3059.       const unsigned char *p;
3060. >     int slen, mlen, renew_ticket = 0;
3061.       unsigned char tick_hmac[EVP_MAX_MD_SIZE];
3062.       HMAC_CTX *hctx = NULL;

ssl/t1_lib.c:3062:5: 
3060.       int slen, mlen, renew_ticket = 0;
3061.       unsigned char tick_hmac[EVP_MAX_MD_SIZE];
3062. >     HMAC_CTX *hctx = NULL;
3063.       EVP_CIPHER_CTX *ctx;
3064.       SSL_CTX *tctx = s->initial_ctx;

ssl/t1_lib.c:3064:5: 
3062.       HMAC_CTX *hctx = NULL;
3063.       EVP_CIPHER_CTX *ctx;
3064. >     SSL_CTX *tctx = s->initial_ctx;
3065.       /* Need at least keyname + iv + some encrypted data */
3066.       if (eticklen < 48)

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

ssl/t1_lib.c:3069:5: 
3067.           return 2;
3068.       /* Initialize session ticket encryption and HMAC contexts */
3069. >     hctx = HMAC_CTX_new();
3070.       if (hctx == NULL)
3071.           return -2;

crypto/hmac/hmac.c:173:1: start of procedure HMAC_CTX_new()
  171.   }
  172.   
  173. > HMAC_CTX *HMAC_CTX_new(void)
  174.   {
  175.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));

crypto/hmac/hmac.c:175:5: 
  173.   HMAC_CTX *HMAC_CTX_new(void)
  174.   {
  175. >     HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
  176.       if (ctx)
  177.           if (!HMAC_CTX_reset(ctx)) {

crypto/mem.c:157:1: start of procedure CRYPTO_zalloc()
    155.   }
    156.   
    157. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:159:5: 
    157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159. >     void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)

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

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

crypto/mem.c:124:9: Taking false branch
      122.       void *ret = NULL;
      123.   
      124.       if (num <= 0)
                     ^
      125.           return NULL;
      126.   

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

crypto/mem.c:137:5: 
      135.       }
      136.   #else
      137. >     (void)file;
      138.       (void)line;
      139.       ret = malloc(num);

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

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

crypto/mem.c:154:5: 
      152.   #endif
      153.   
      154. >     return ret;
      155.   }
      156.   

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
      153.   
      154.       return ret;
      155. > }
      156.   
      157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:161:9: Taking true branch
    159.       void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)
                   ^
    162.           memset(ret, 0, num);
    163.       return ret;

crypto/mem.c:162:9: 
    160.   
    161.       if (ret != NULL)
    162. >         memset(ret, 0, num);
    163.       return ret;
    164.   }

crypto/mem.c:163:5: 
    161.       if (ret != NULL)
    162.           memset(ret, 0, num);
    163. >     return ret;
    164.   }
    165.   

crypto/mem.c:164:1: return from a call to CRYPTO_zalloc
    162.           memset(ret, 0, num);
    163.       return ret;
    164. > }
    165.   
    166.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/hmac/hmac.c:176:9: Taking true branch
  174.   {
  175.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
  176.       if (ctx)
                 ^
  177.           if (!HMAC_CTX_reset(ctx)) {
  178.               HMAC_CTX_free(ctx);

crypto/hmac/hmac.c:177:14: Taking false branch
  175.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
  176.       if (ctx)
  177.           if (!HMAC_CTX_reset(ctx)) {
                      ^
  178.               HMAC_CTX_free(ctx);
  179.               ctx = NULL;

crypto/hmac/hmac.c:181:5: 
  179.               ctx = NULL;
  180.           }
  181. >     return ctx;
  182.   }
  183.   

crypto/hmac/hmac.c:182:1: return from a call to HMAC_CTX_new
  180.           }
  181.       return ctx;
  182. > }
  183.   
  184.   static void hmac_ctx_cleanup(HMAC_CTX *ctx)

ssl/t1_lib.c:3070:9: Taking false branch
3068.       /* Initialize session ticket encryption and HMAC contexts */
3069.       hctx = HMAC_CTX_new();
3070.       if (hctx == NULL)
                ^
3071.           return -2;
3072.       ctx = EVP_CIPHER_CTX_new();

ssl/t1_lib.c:3072:5: 
3070.       if (hctx == NULL)
3071.           return -2;
3072. >     ctx = EVP_CIPHER_CTX_new();
3073.       if (tctx->tlsext_ticket_key_cb) {
3074.           unsigned char *nctick = (unsigned char *)etick;

crypto/evp/evp_enc.c:93:1: start of procedure EVP_CIPHER_CTX_new()
  91.   }
  92.   
  93. > EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  94.   {
  95.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));

crypto/evp/evp_enc.c:95:5: 
  93.   EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  94.   {
  95. >     return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  96.   }
  97.   

crypto/mem.c:157:1: start of procedure CRYPTO_zalloc()
    155.   }
    156.   
    157. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:159:5: 
    157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159. >     void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)

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

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

crypto/mem.c:124:9: Taking false branch
      122.       void *ret = NULL;
      123.   
      124.       if (num <= 0)
                     ^
      125.           return NULL;
      126.   

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

crypto/mem.c:137:5: 
      135.       }
      136.   #else
      137. >     (void)file;
      138.       (void)line;
      139.       ret = malloc(num);

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

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

crypto/mem.c:154:5: 
      152.   #endif
      153.   
      154. >     return ret;
      155.   }
      156.   

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
      153.   
      154.       return ret;
      155. > }
      156.   
      157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:161:9: Taking true branch
    159.       void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)
                   ^
    162.           memset(ret, 0, num);
    163.       return ret;

crypto/mem.c:162:9: 
    160.   
    161.       if (ret != NULL)
    162. >         memset(ret, 0, num);
    163.       return ret;
    164.   }

crypto/mem.c:163:5: 
    161.       if (ret != NULL)
    162.           memset(ret, 0, num);
    163. >     return ret;
    164.   }
    165.   

crypto/mem.c:164:1: return from a call to CRYPTO_zalloc
    162.           memset(ret, 0, num);
    163.       return ret;
    164. > }
    165.   
    166.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/evp_enc.c:96:1: return from a call to EVP_CIPHER_CTX_new
  94.   {
  95.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  96. > }
  97.   
  98.   void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)

ssl/t1_lib.c:3073:9: Taking true branch
3071.           return -2;
3072.       ctx = EVP_CIPHER_CTX_new();
3073.       if (tctx->tlsext_ticket_key_cb) {
                ^
3074.           unsigned char *nctick = (unsigned char *)etick;
3075.           int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,

ssl/t1_lib.c:3074:9: 
3072.       ctx = EVP_CIPHER_CTX_new();
3073.       if (tctx->tlsext_ticket_key_cb) {
3074. >         unsigned char *nctick = (unsigned char *)etick;
3075.           int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,
3076.                                               ctx, hctx, 0);

ssl/t1_lib.c:3075:9: Skipping __function_pointer__(): unresolved function pointer
3073.       if (tctx->tlsext_ticket_key_cb) {
3074.           unsigned char *nctick = (unsigned char *)etick;
3075.           int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,
                ^
3076.                                               ctx, hctx, 0);
3077.           if (rv < 0)

ssl/t1_lib.c:3077:13: Taking false branch
3075.           int rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,
3076.                                               ctx, hctx, 0);
3077.           if (rv < 0)
                    ^
3078.               return -1;
3079.           if (rv == 0)

ssl/t1_lib.c:3079:13: Taking true branch
3077.           if (rv < 0)
3078.               return -1;
3079.           if (rv == 0)
                    ^
3080.               return 2;
3081.           if (rv == 2)

ssl/t1_lib.c:3080:13: 
3078.               return -1;
3079.           if (rv == 0)
3080. >             return 2;
3081.           if (rv == 2)
3082.               renew_ticket = 1;

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;
    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 (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)
            return -1;
        if (rv == 0)
            return 2;
        if (rv == 2)
            renew_ticket = 1;
    } else {
        if (memcmp(etick, tctx->tlsext_tick_key_name, 16))
            return 2;
        if (HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key, 16,
                         EVP_sha256(), NULL) <= 0
                || EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL,
                                      tctx->tlsext_tick_aes_key,
                                      etick + 16) <= 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);
        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 -1;
}
['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;\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 (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            return -1;\n        if (rv == 0)\n            return 2;\n        if (rv == 2)\n            renew_ticket = 1;\n    } else {\n        if (memcmp(etick, tctx->tlsext_tick_key_name, 16))\n            return 2;\n        if (HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key, 16,\n                         EVP_sha256(), NULL) <= 0\n                || EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL,\n                                      tctx->tlsext_tick_aes_key,\n                                      etick + 16) <= 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        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 -1;\n}', 'HMAC_CTX *HMAC_CTX_new(void)\n{\n    HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));\n    if (ctx)\n        if (!HMAC_CTX_reset(ctx)) {\n            HMAC_CTX_free(ctx);\n            ctx = NULL;\n        }\n    return 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 (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}', 'EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));\n}']