ssl/tls13_enc.c:760: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 714, column 23 is not reachable after line 760, column 5.
Showing all 56 steps of the trace


ssl/tls13_enc.c:705:1: start of procedure tls13_export_keying_material_early()
703.   }
704.   
705. > int tls13_export_keying_material_early(SSL *s, unsigned char *out, size_t olen,
706.                                          const char *label, size_t llen,
707.                                          const unsigned char *context,

ssl/tls13_enc.c:710:5: 
708.                                          size_t contextlen)
709.   {
710. >     static const unsigned char exporterlabel[] = "exporter";
711.       unsigned char exportsecret[EVP_MAX_MD_SIZE];
712.       unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];

ssl/tls13_enc.c:714:5: 
712.       unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];
713.       const EVP_MD *md;
714. >     EVP_MD_CTX *ctx = EVP_MD_CTX_new();
715.       unsigned int hashsize, datalen;
716.       int ret = 0;

crypto/evp/digest.c:44:1: start of procedure EVP_MD_CTX_new()
  42.   }
  43.   
  44. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:46:5: 
  44.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47.   }
  48.   

crypto/mem.c:221:1: start of procedure CRYPTO_zalloc()
    219.   }
    220.   
    221. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    222.   {
    223.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:223:5: 
    221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    222.   {
    223. >     void *ret = CRYPTO_malloc(num, file, line);
    224.   
    225.       FAILTEST();

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
      190.   #endif
      191.   
      192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194.       void *ret = NULL;

crypto/mem.c:194:5: 
      192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194. >     void *ret = NULL;
      195.   
      196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
      195.   
      196.       INCREMENT(malloc_count);
      197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      198.           return malloc_impl(num, file, line);
      199.   

crypto/mem.c:200:9: Taking false branch
      198.           return malloc_impl(num, file, line);
      199.   
      200.       if (num == 0)
                     ^
      201.           return NULL;
      202.   

crypto/mem.c:204:5: 
      202.   
      203.       FAILTEST();
      204. >     allow_customize = 0;
      205.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      206.       if (call_malloc_debug) {

crypto/mem.c:214:5: 
      212.       }
      213.   #else
      214. >     (void)(file); (void)(line);
      215.       ret = malloc(num);
      216.   #endif

crypto/mem.c:214:19: 
      212.       }
      213.   #else
      214. >     (void)(file); (void)(line);
      215.       ret = malloc(num);
      216.   #endif

crypto/mem.c:215:5: 
      213.   #else
      214.       (void)(file); (void)(line);
      215. >     ret = malloc(num);
      216.   #endif
      217.   

crypto/mem.c:218:5: 
      216.   #endif
      217.   
      218. >     return ret;
      219.   }
      220.   

crypto/mem.c:219:1: return from a call to CRYPTO_malloc
      217.   
      218.       return ret;
      219. > }
      220.   
      221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:226:9: Taking true branch
    224.   
    225.       FAILTEST();
    226.       if (ret != NULL)
                   ^
    227.           memset(ret, 0, num);
    228.       return ret;

crypto/mem.c:227:9: 
    225.       FAILTEST();
    226.       if (ret != NULL)
    227. >         memset(ret, 0, num);
    228.       return ret;
    229.   }

crypto/mem.c:228:5: 
    226.       if (ret != NULL)
    227.           memset(ret, 0, num);
    228. >     return ret;
    229.   }
    230.   

crypto/mem.c:229:1: return from a call to CRYPTO_zalloc
    227.           memset(ret, 0, num);
    228.       return ret;
    229. > }
    230.   
    231.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:47:1: return from a call to EVP_MD_CTX_new
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47. > }
  48.   
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

ssl/tls13_enc.c:716:5: 
714.       EVP_MD_CTX *ctx = EVP_MD_CTX_new();
715.       unsigned int hashsize, datalen;
716. >     int ret = 0;
717.       const SSL_CIPHER *sslcipher;
718.   

ssl/tls13_enc.c:719:9: Taking false branch
717.       const SSL_CIPHER *sslcipher;
718.   
719.       if (ctx == NULL || !ossl_statem_export_early_allowed(s))
               ^
720.           goto err;
721.   

ssl/tls13_enc.c:719:25: 
717.       const SSL_CIPHER *sslcipher;
718.   
719. >     if (ctx == NULL || !ossl_statem_export_early_allowed(s))
720.           goto err;
721.   

test/tls13secretstest.c:220:1: start of procedure ossl_statem_export_early_allowed()
  218.   }
  219.   
  220. > int ossl_statem_export_early_allowed(SSL *s)
  221.   {
  222.       return 1;

test/tls13secretstest.c:222:5: 
  220.   int ossl_statem_export_early_allowed(SSL *s)
  221.   {
  222. >     return 1;
  223.   }
  224.   

test/tls13secretstest.c:223:1: return from a call to ossl_statem_export_early_allowed
  221.   {
  222.       return 1;
  223. > }
  224.   
  225.   /* End of mocked out code */

ssl/tls13_enc.c:719:25: Taking false branch
717.       const SSL_CIPHER *sslcipher;
718.   
719.       if (ctx == NULL || !ossl_statem_export_early_allowed(s))
                               ^
720.           goto err;
721.   

ssl/tls13_enc.c:722:10: Taking true branch
720.           goto err;
721.   
722.       if (!s->server && s->max_early_data > 0
                ^
723.               && s->session->ext.max_early_data == 0)
724.           sslcipher = SSL_SESSION_get0_cipher(s->psksession);

ssl/tls13_enc.c:722:23: Taking true branch
720.           goto err;
721.   
722.       if (!s->server && s->max_early_data > 0
                             ^
723.               && s->session->ext.max_early_data == 0)
724.           sslcipher = SSL_SESSION_get0_cipher(s->psksession);

ssl/tls13_enc.c:723:16: Taking true branch
721.   
722.       if (!s->server && s->max_early_data > 0
723.               && s->session->ext.max_early_data == 0)
                      ^
724.           sslcipher = SSL_SESSION_get0_cipher(s->psksession);
725.       else

ssl/tls13_enc.c:724:9: 
722.       if (!s->server && s->max_early_data > 0
723.               && s->session->ext.max_early_data == 0)
724. >         sslcipher = SSL_SESSION_get0_cipher(s->psksession);
725.       else
726.           sslcipher = SSL_SESSION_get0_cipher(s->session);

ssl/ssl_sess.c:898:1: start of procedure SSL_SESSION_get0_cipher()
  896.   }
  897.   
  898. > const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s)
  899.   {
  900.       return s->cipher;

ssl/ssl_sess.c:900:5: 
  898.   const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s)
  899.   {
  900. >     return s->cipher;
  901.   }
  902.   

ssl/ssl_sess.c:901:1: return from a call to SSL_SESSION_get0_cipher
  899.   {
  900.       return s->cipher;
  901. > }
  902.   
  903.   int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher)

ssl/tls13_enc.c:728:5: 
726.           sslcipher = SSL_SESSION_get0_cipher(s->session);
727.   
728. >     md = ssl_md(sslcipher->algorithm2);
729.   
730.       /*

test/tls13secretstest.c:205:1: start of procedure ssl_md()
  203.   }
  204.   
  205. > const EVP_MD *ssl_md(int idx)
  206.   {
  207.       return EVP_sha256();

test/tls13secretstest.c:207:5: 
  205.   const EVP_MD *ssl_md(int idx)
  206.   {
  207. >     return EVP_sha256();
  208.   }
  209.   

crypto/evp/m_sha1.c:177:1: start of procedure EVP_sha256()
    175.   };
    176.   
    177. > const EVP_MD *EVP_sha256(void)
    178.   {
    179.       return &sha256_md;

crypto/evp/m_sha1.c:179:5: 
    177.   const EVP_MD *EVP_sha256(void)
    178.   {
    179. >     return &sha256_md;
    180.   }
    181.   

crypto/evp/m_sha1.c:180:1: return from a call to EVP_sha256
    178.   {
    179.       return &sha256_md;
    180. > }
    181.   
    182.   static int init512_224(EVP_MD_CTX *ctx)

test/tls13secretstest.c:208:1: return from a call to ssl_md
  206.   {
  207.       return EVP_sha256();
  208. > }
  209.   
  210.   void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,

ssl/tls13_enc.c:745:9: Taking true branch
743.        * Here Transcript-Hash is the cipher suite hash algorithm.
744.        */
745.       if (EVP_DigestInit_ex(ctx, md, NULL) <= 0
               ^
746.               || EVP_DigestUpdate(ctx, context, contextlen) <= 0
747.               || EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0

ssl/tls13_enc.c:759:2: 
757.   
758.       ret = 1;
759. >  err:
760.       EVP_MD_CTX_free(ctx);
761.       return ret;

ssl/tls13_enc.c:760:5: 
758.       ret = 1;
759.    err:
760. >     EVP_MD_CTX_free(ctx);
761.       return ret;
762.   }

crypto/evp/digest.c:49:1: start of procedure EVP_MD_CTX_free()
  47.   }
  48.   
  49. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:51:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
            ^
  52.       OPENSSL_free(ctx);
  53.   }

crypto/evp/digest.c:52:5: 
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
  52. >     OPENSSL_free(ctx);
  53.   }
  54.   

crypto/mem.c:289:1: start of procedure CRYPTO_free()
    287.   }
    288.   
    289. > void CRYPTO_free(void *str, const char *file, int line)
    290.   {
    291.       INCREMENT(free_count);

crypto/mem.c:292:9: Taking true branch
    290.   {
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    293.           free_impl(str, file, line);
    294.           return;

crypto/mem.c:292:30: Taking true branch
    290.   {
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    293.           free_impl(str, file, line);
    294.           return;

crypto/mem.c:293:9: Skipping __function_pointer__(): unresolved function pointer
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    293.           free_impl(str, file, line);
                   ^
    294.           return;
    295.       }

crypto/mem.c:294:9: 
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    293.           free_impl(str, file, line);
    294. >         return;
    295.       }
    296.   

crypto/mem.c:308:1: return from a call to CRYPTO_free
    306.       free(str);
    307.   #endif
    308. > }
    309.   
    310.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:53:1: return from a call to EVP_MD_CTX_free
  51.       EVP_MD_CTX_reset(ctx);
  52.       OPENSSL_free(ctx);
  53. > }
  54.   
  55.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

int tls13_export_keying_material_early(SSL *s, unsigned char *out, size_t olen,
                                       const char *label, size_t llen,
                                       const unsigned char *context,
                                       size_t contextlen)
{
    static const unsigned char exporterlabel[] = "exporter";
    unsigned char exportsecret[EVP_MAX_MD_SIZE];
    unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];
    const EVP_MD *md;
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    unsigned int hashsize, datalen;
    int ret = 0;
    const SSL_CIPHER *sslcipher;
    if (ctx == NULL || !ossl_statem_export_early_allowed(s))
        goto err;
    if (!s->server && s->max_early_data > 0
            && s->session->ext.max_early_data == 0)
        sslcipher = SSL_SESSION_get0_cipher(s->psksession);
    else
        sslcipher = SSL_SESSION_get0_cipher(s->session);
    md = ssl_md(sslcipher->algorithm2);
    if (EVP_DigestInit_ex(ctx, md, NULL) <= 0
            || EVP_DigestUpdate(ctx, context, contextlen) <= 0
            || EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0
            || EVP_DigestInit_ex(ctx, md, NULL) <= 0
            || EVP_DigestFinal_ex(ctx, data, &datalen) <= 0
            || !tls13_hkdf_expand(s, md, s->early_exporter_master_secret,
                                  (const unsigned char *)label, llen,
                                  data, datalen, exportsecret, hashsize)
            || !tls13_hkdf_expand(s, md, exportsecret, exporterlabel,
                                  sizeof(exporterlabel) - 1, hash, hashsize,
                                  out, olen))
        goto err;
    ret = 1;
 err:
    EVP_MD_CTX_free(ctx);
    return ret;
}
['int tls13_export_keying_material_early(SSL *s, unsigned char *out, size_t olen,\n                                       const char *label, size_t llen,\n                                       const unsigned char *context,\n                                       size_t contextlen)\n{\n    static const unsigned char exporterlabel[] = "exporter";\n    unsigned char exportsecret[EVP_MAX_MD_SIZE];\n    unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];\n    const EVP_MD *md;\n    EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n    unsigned int hashsize, datalen;\n    int ret = 0;\n    const SSL_CIPHER *sslcipher;\n    if (ctx == NULL || !ossl_statem_export_early_allowed(s))\n        goto err;\n    if (!s->server && s->max_early_data > 0\n            && s->session->ext.max_early_data == 0)\n        sslcipher = SSL_SESSION_get0_cipher(s->psksession);\n    else\n        sslcipher = SSL_SESSION_get0_cipher(s->session);\n    md = ssl_md(sslcipher->algorithm2);\n    if (EVP_DigestInit_ex(ctx, md, NULL) <= 0\n            || EVP_DigestUpdate(ctx, context, contextlen) <= 0\n            || EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0\n            || EVP_DigestInit_ex(ctx, md, NULL) <= 0\n            || EVP_DigestFinal_ex(ctx, data, &datalen) <= 0\n            || !tls13_hkdf_expand(s, md, s->early_exporter_master_secret,\n                                  (const unsigned char *)label, llen,\n                                  data, datalen, exportsecret, hashsize)\n            || !tls13_hkdf_expand(s, md, exportsecret, exporterlabel,\n                                  sizeof(exporterlabel) - 1, hash, hashsize,\n                                  out, olen))\n        goto err;\n    ret = 1;\n err:\n    EVP_MD_CTX_free(ctx);\n    return ret;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\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    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\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); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'int ossl_statem_export_early_allowed(SSL *s)\n{\n    return 1;\n}', 'const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s)\n{\n    return s->cipher;\n}', 'const EVP_MD *ssl_md(int idx)\n{\n    return EVP_sha256();\n}', 'const EVP_MD *EVP_sha256(void)\n{\n    return &sha256_md;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    INCREMENT(free_count);\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}']