crypto/ct/ct_oct.c:149: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_memdup()` at line 104, column 23 is not reachable after line 149, column 5.
Showing all 70 steps of the trace


crypto/ct/ct_oct.c:70:1: start of procedure o2i_SCT()
68.   }
69.   
70. > SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len)
71.   {
72.       SCT *sct = NULL;

crypto/ct/ct_oct.c:72:5: 
70.   SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len)
71.   {
72. >     SCT *sct = NULL;
73.       const unsigned char *p;
74.   

crypto/ct/ct_oct.c:75:9: Taking false branch
73.       const unsigned char *p;
74.   
75.       if (len == 0 || len > MAX_SCT_SIZE) {
              ^
76.           CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
77.           goto err;

crypto/ct/ct_oct.c:75:21: Taking false branch
73.       const unsigned char *p;
74.   
75.       if (len == 0 || len > MAX_SCT_SIZE) {
                          ^
76.           CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
77.           goto err;

crypto/ct/ct_oct.c:80:9: Taking false branch
78.       }
79.   
80.       if ((sct = SCT_new()) == NULL)
              ^
81.           goto err;
82.   

crypto/ct/ct_oct.c:83:5: 
81.           goto err;
82.   
83. >     p = *in;
84.   
85.       sct->version = *p;

crypto/ct/ct_oct.c:85:5: 
83.       p = *in;
84.   
85. >     sct->version = *p;
86.       if (sct->version == SCT_VERSION_V1) {
87.           int sig_len;

crypto/ct/ct_oct.c:86:9: Taking true branch
84.   
85.       sct->version = *p;
86.       if (sct->version == SCT_VERSION_V1) {
              ^
87.           int sig_len;
88.           size_t len2;

crypto/ct/ct_oct.c:98:13: Taking false branch
96.            *   }
97.            */
98.           if (len < 43) {
                   ^
99.               CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
100.               goto err;

crypto/ct/ct_oct.c:102:9: 
100.               goto err;
101.           }
102. >         len -= 43;
103.           p++;
104.           sct->log_id = BUF_memdup(p, CT_V1_HASHLEN);

crypto/ct/ct_oct.c:103:9: 
101.           }
102.           len -= 43;
103. >         p++;
104.           sct->log_id = BUF_memdup(p, CT_V1_HASHLEN);
105.           if (sct->log_id == NULL)

crypto/ct/ct_oct.c:104:9: 
102.           len -= 43;
103.           p++;
104. >         sct->log_id = BUF_memdup(p, CT_V1_HASHLEN);
105.           if (sct->log_id == NULL)
106.               goto err;

crypto/o_str.c:60:1: start of procedure CRYPTO_memdup()
  58.   }
  59.   
  60. > void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line)
  61.   {
  62.       void *ret;

crypto/o_str.c:64:9: Taking false branch
  62.       void *ret;
  63.   
  64.       if (data == NULL || siz >= INT_MAX)
                ^
  65.           return NULL;
  66.   

crypto/o_str.c:64:25: Taking false branch
  62.       void *ret;
  63.   
  64.       if (data == NULL || siz >= INT_MAX)
                                ^
  65.           return NULL;
  66.   

crypto/o_str.c:67:5: 
  65.           return NULL;
  66.   
  67. >     ret = CRYPTO_malloc(siz, file, line);
  68.       if (ret == NULL) {
  69.           CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);

crypto/mem.c:169:1: start of procedure CRYPTO_malloc()
    167.   #endif
    168.   
    169. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    170.   {
    171.       void *ret = NULL;

crypto/mem.c:171:5: 
    169.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    170.   {
    171. >     void *ret = NULL;
    172.   
    173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:173:9: Taking false branch
    171.       void *ret = NULL;
    172.   
    173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                   ^
    174.           return malloc_impl(num, file, line);
    175.   

crypto/mem.c:176:9: Taking false branch
    174.           return malloc_impl(num, file, line);
    175.   
    176.       if (num == 0)
                   ^
    177.           return NULL;
    178.   

crypto/mem.c:180:5: 
    178.   
    179.       FAILTEST();
    180. >     allow_customize = 0;
    181.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
    182.       if (call_malloc_debug) {

crypto/mem.c:190:5: 
    188.       }
    189.   #else
    190. >     osslargused(file); osslargused(line);
    191.       ret = malloc(num);
    192.   #endif

crypto/mem.c:190:24: 
    188.       }
    189.   #else
    190. >     osslargused(file); osslargused(line);
    191.       ret = malloc(num);
    192.   #endif

crypto/mem.c:191:5: 
    189.   #else
    190.       osslargused(file); osslargused(line);
    191. >     ret = malloc(num);
    192.   #endif
    193.   

crypto/mem.c:194:5: 
    192.   #endif
    193.   
    194. >     return ret;
    195.   }
    196.   

crypto/mem.c:195:1: return from a call to CRYPTO_malloc
    193.   
    194.       return ret;
    195. > }
    196.   
    197.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/o_str.c:68:9: Taking false branch
  66.   
  67.       ret = CRYPTO_malloc(siz, file, line);
  68.       if (ret == NULL) {
                ^
  69.           CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);
  70.           return NULL;

crypto/o_str.c:72:5: 
  70.           return NULL;
  71.       }
  72. >     return memcpy(ret, data, siz);
  73.   }
  74.   

crypto/o_str.c:73:1: return from a call to CRYPTO_memdup
  71.       }
  72.       return memcpy(ret, data, siz);
  73. > }
  74.   
  75.   size_t OPENSSL_strnlen(const char *str, size_t maxlen)

crypto/ct/ct_oct.c:105:13: Taking false branch
103.           p++;
104.           sct->log_id = BUF_memdup(p, CT_V1_HASHLEN);
105.           if (sct->log_id == NULL)
                   ^
106.               goto err;
107.           sct->log_id_len = CT_V1_HASHLEN;

crypto/ct/ct_oct.c:107:9: 
105.           if (sct->log_id == NULL)
106.               goto err;
107. >         sct->log_id_len = CT_V1_HASHLEN;
108.           p += CT_V1_HASHLEN;
109.   

crypto/ct/ct_oct.c:108:9: 
106.               goto err;
107.           sct->log_id_len = CT_V1_HASHLEN;
108. >         p += CT_V1_HASHLEN;
109.   
110.           n2l8(p, sct->timestamp);

crypto/ct/ct_oct.c:110:9: 
108.           p += CT_V1_HASHLEN;
109.   
110. >         n2l8(p, sct->timestamp);
111.   
112.           n2s(p, len2);

crypto/ct/ct_oct.c:112:9: 
110.           n2l8(p, sct->timestamp);
111.   
112. >         n2s(p, len2);
113.           if (len < len2) {
114.               CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);

crypto/ct/ct_oct.c:113:13: Taking false branch
111.   
112.           n2s(p, len2);
113.           if (len < len2) {
                   ^
114.               CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
115.               goto err;

crypto/ct/ct_oct.c:117:13: Taking true branch
115.               goto err;
116.           }
117.           if (len2 > 0) {
                   ^
118.               sct->ext = BUF_memdup(p, len2);
119.               if (sct->ext == NULL)

crypto/ct/ct_oct.c:118:13: 
116.           }
117.           if (len2 > 0) {
118. >             sct->ext = BUF_memdup(p, len2);
119.               if (sct->ext == NULL)
120.                   goto err;

crypto/o_str.c:60:1: start of procedure CRYPTO_memdup()
  58.   }
  59.   
  60. > void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line)
  61.   {
  62.       void *ret;

crypto/o_str.c:64:9: Taking false branch
  62.       void *ret;
  63.   
  64.       if (data == NULL || siz >= INT_MAX)
                ^
  65.           return NULL;
  66.   

crypto/o_str.c:64:25: Taking false branch
  62.       void *ret;
  63.   
  64.       if (data == NULL || siz >= INT_MAX)
                                ^
  65.           return NULL;
  66.   

crypto/o_str.c:67:5: 
  65.           return NULL;
  66.   
  67. >     ret = CRYPTO_malloc(siz, file, line);
  68.       if (ret == NULL) {
  69.           CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);

crypto/mem.c:169:1: start of procedure CRYPTO_malloc()
    167.   #endif
    168.   
    169. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    170.   {
    171.       void *ret = NULL;

crypto/mem.c:171:5: 
    169.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    170.   {
    171. >     void *ret = NULL;
    172.   
    173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:173:9: Taking true branch
    171.       void *ret = NULL;
    172.   
    173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                   ^
    174.           return malloc_impl(num, file, line);
    175.   

crypto/mem.c:173:32: Taking true branch
    171.       void *ret = NULL;
    172.   
    173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                                          ^
    174.           return malloc_impl(num, file, line);
    175.   

crypto/mem.c:174:9: Skipping __function_pointer__(): unresolved function pointer
    172.   
    173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
    174.           return malloc_impl(num, file, line);
                   ^
    175.   
    176.       if (num == 0)

crypto/mem.c:195:1: return from a call to CRYPTO_malloc
    193.   
    194.       return ret;
    195. > }
    196.   
    197.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/o_str.c:68:9: Taking true branch
  66.   
  67.       ret = CRYPTO_malloc(siz, file, line);
  68.       if (ret == NULL) {
                ^
  69.           CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);
  70.           return NULL;

crypto/o_str.c:69:9: 
  67.       ret = CRYPTO_malloc(siz, file, line);
  68.       if (ret == NULL) {
  69. >         CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);
  70.           return NULL;
  71.       }

crypto/err/err.c:365:1: start of procedure ERR_put_error()
    363.   /********************************************************/
    364.   
    365. > void ERR_put_error(int lib, int func, int reason, const char *file, int line)
    366.   {
    367.       ERR_STATE *es;

crypto/err/err.c:388:5: 
    386.       }
    387.   #endif
    388. >     es = ERR_get_state();
    389.       if (es == NULL)
    390.           return;

crypto/err/err.c:679:1: start of procedure ERR_get_state()
      677.   }
      678.   
      679. > ERR_STATE *ERR_get_state(void)
      680.   {
      681.       ERR_STATE *state = NULL;

crypto/err/err.c:681:5: 
      679.   ERR_STATE *ERR_get_state(void)
      680.   {
      681. >     ERR_STATE *state = NULL;
      682.   
      683.       if (!RUN_ONCE(&err_init, err_do_init))

crypto/err/err.c:683:10: 
      681.       ERR_STATE *state = NULL;
      682.   
      683. >     if (!RUN_ONCE(&err_init, err_do_init))
      684.           return NULL;
      685.   

crypto/threads_pthread.c:105:1: start of procedure CRYPTO_THREAD_run_once()
        103.   }
        104.   
        105. > int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
        106.   {
        107.       if (pthread_once(once, init) != 0)

crypto/threads_pthread.c:107:9: Taking true branch
        105.   int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
        106.   {
        107.       if (pthread_once(once, init) != 0)
                       ^
        108.           return 0;
        109.   

crypto/threads_pthread.c:108:9: 
        106.   {
        107.       if (pthread_once(once, init) != 0)
        108. >         return 0;
        109.   
        110.       return 1;

crypto/threads_pthread.c:111:1: return from a call to CRYPTO_THREAD_run_once
        109.   
        110.       return 1;
        111. > }
        112.   
        113.   int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))

crypto/err/err.c:683:10: Condition is false
      681.       ERR_STATE *state = NULL;
      682.   
      683.       if (!RUN_ONCE(&err_init, err_do_init))
                      ^
      684.           return NULL;
      685.   

crypto/err/err.c:683:10: Taking true branch
      681.       ERR_STATE *state = NULL;
      682.   
      683.       if (!RUN_ONCE(&err_init, err_do_init))
                      ^
      684.           return NULL;
      685.   

crypto/err/err.c:684:9: 
      682.   
      683.       if (!RUN_ONCE(&err_init, err_do_init))
      684. >         return NULL;
      685.   
      686.       state = CRYPTO_THREAD_get_local(&err_thread_local);

crypto/err/err.c:704:1: return from a call to ERR_get_state
      702.   
      703.       return state;
      704. > }
      705.   
      706.   int ERR_get_next_error_library(void)

crypto/err/err.c:389:9: Taking true branch
    387.   #endif
    388.       es = ERR_get_state();
    389.       if (es == NULL)
                   ^
    390.           return;
    391.   

crypto/err/err.c:390:9: 
    388.       es = ERR_get_state();
    389.       if (es == NULL)
    390. >         return;
    391.   
    392.       es->top = (es->top + 1) % ERR_NUM_ERRORS;

crypto/err/err.c:400:1: return from a call to ERR_put_error
    398.       es->err_line[es->top] = line;
    399.       err_clear_data(es, es->top);
    400. > }
    401.   
    402.   void ERR_clear_error(void)

crypto/o_str.c:70:9: 
  68.       if (ret == NULL) {
  69.           CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);
  70. >         return NULL;
  71.       }
  72.       return memcpy(ret, data, siz);

crypto/o_str.c:73:1: return from a call to CRYPTO_memdup
  71.       }
  72.       return memcpy(ret, data, siz);
  73. > }
  74.   
  75.   size_t OPENSSL_strnlen(const char *str, size_t maxlen)

crypto/ct/ct_oct.c:119:17: Taking true branch
117.           if (len2 > 0) {
118.               sct->ext = BUF_memdup(p, len2);
119.               if (sct->ext == NULL)
                       ^
120.                   goto err;
121.           }

crypto/ct/ct_oct.c:148:1: 
146.   
147.       return sct;
148. > err:
149.       SCT_free(sct);
150.       return NULL;

crypto/ct/ct_oct.c:149:5: Skipping SCT_free(): empty list of specs
147.       return sct;
148.   err:
149.       SCT_free(sct);
           ^
150.       return NULL;
151.   }

SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len)
{
    SCT *sct = NULL;
    const unsigned char *p;
    if (len == 0 || len > MAX_SCT_SIZE) {
        CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
        goto err;
    }
    if ((sct = SCT_new()) == NULL)
        goto err;
    p = *in;
    sct->version = *p;
    if (sct->version == SCT_VERSION_V1) {
        int sig_len;
        size_t len2;
        if (len < 43) {
            CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
            goto err;
        }
        len -= 43;
        p++;
        sct->log_id = BUF_memdup(p, CT_V1_HASHLEN);
        if (sct->log_id == NULL)
            goto err;
        sct->log_id_len = CT_V1_HASHLEN;
        p += CT_V1_HASHLEN;
        n2l8(p, sct->timestamp);
        n2s(p, len2);
        if (len < len2) {
            CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
            goto err;
        }
        if (len2 > 0) {
            sct->ext = BUF_memdup(p, len2);
            if (sct->ext == NULL)
                goto err;
        }
        sct->ext_len = len2;
        p += len2;
        len -= len2;
        sig_len = o2i_SCT_signature(sct, &p, len);
        if (sig_len <= 0) {
            CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);
            goto err;
        }
        len -= sig_len;
        *in = p + len;
    } else {
        sct->sct = BUF_memdup(p, len);
        if (sct->sct == NULL)
            goto err;
        sct->sct_len = len;
        *in = p + len;
    }
    if (psct != NULL) {
        SCT_free(*psct);
        *psct = sct;
    }
    return sct;
err:
    SCT_free(sct);
    return NULL;
}
['SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len)\n{\n    SCT *sct = NULL;\n    const unsigned char *p;\n    if (len == 0 || len > MAX_SCT_SIZE) {\n        CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);\n        goto err;\n    }\n    if ((sct = SCT_new()) == NULL)\n        goto err;\n    p = *in;\n    sct->version = *p;\n    if (sct->version == SCT_VERSION_V1) {\n        int sig_len;\n        size_t len2;\n        if (len < 43) {\n            CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);\n            goto err;\n        }\n        len -= 43;\n        p++;\n        sct->log_id = BUF_memdup(p, CT_V1_HASHLEN);\n        if (sct->log_id == NULL)\n            goto err;\n        sct->log_id_len = CT_V1_HASHLEN;\n        p += CT_V1_HASHLEN;\n        n2l8(p, sct->timestamp);\n        n2s(p, len2);\n        if (len < len2) {\n            CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);\n            goto err;\n        }\n        if (len2 > 0) {\n            sct->ext = BUF_memdup(p, len2);\n            if (sct->ext == NULL)\n                goto err;\n        }\n        sct->ext_len = len2;\n        p += len2;\n        len -= len2;\n        sig_len = o2i_SCT_signature(sct, &p, len);\n        if (sig_len <= 0) {\n            CTerr(CT_F_O2I_SCT, CT_R_SCT_INVALID);\n            goto err;\n        }\n        len -= sig_len;\n        *in = p + len;\n    } else {\n        sct->sct = BUF_memdup(p, len);\n        if (sct->sct == NULL)\n            goto err;\n        sct->sct_len = len;\n        *in = p + len;\n    }\n    if (psct != NULL) {\n        SCT_free(*psct);\n        *psct = sct;\n    }\n    return sct;\nerr:\n    SCT_free(sct);\n    return NULL;\n}', 'void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line)\n{\n    void *ret;\n    if (data == NULL || siz >= INT_MAX)\n        return NULL;\n    ret = CRYPTO_malloc(siz, file, line);\n    if (ret == NULL) {\n        CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    return memcpy(ret, data, siz);\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    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    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'void ERR_put_error(int lib, int func, int reason, const char *file, int line)\n{\n    ERR_STATE *es;\n#ifdef _OSD_POSIX\n    if (strncmp(file, "*POSIX(", sizeof("*POSIX(") - 1) == 0) {\n        char *end;\n        file += sizeof("*POSIX(") - 1;\n        end = &file[strlen(file) - 1];\n        if (*end == \')\')\n            *end = \'\\0\';\n        if ((end = strrchr(file, \'/\')) != NULL)\n            file = &end[1];\n    }\n#endif\n    es = ERR_get_state();\n    if (es == NULL)\n        return;\n    es->top = (es->top + 1) % ERR_NUM_ERRORS;\n    if (es->top == es->bottom)\n        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;\n    es->err_flags[es->top] = 0;\n    es->err_buffer[es->top] = ERR_PACK(lib, func, reason);\n    es->err_file[es->top] = file;\n    es->err_line[es->top] = line;\n    err_clear_data(es, es->top);\n}', 'ERR_STATE *ERR_get_state(void)\n{\n    ERR_STATE *state = NULL;\n    if (!RUN_ONCE(&err_init, err_do_init))\n        return NULL;\n    state = CRYPTO_THREAD_get_local(&err_thread_local);\n    if (state == NULL) {\n        state = OPENSSL_zalloc(sizeof(*state));\n        if (state == NULL)\n            return NULL;\n        if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)\n            || !CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n            ERR_STATE_free(state);\n            return NULL;\n        }\n        OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n    }\n    return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n    if (pthread_once(once, init) != 0)\n        return 0;\n    return 1;\n}']