ssl/ssl_cert.c:472: error: USE_AFTER_FREE
  call to `sk_X509_NAME_free()` eventually accesses memory that was invalidated by call to `free()` on line 471 indirectly during the call to `sk_X509_NAME_reserve()`.
Showing all 22 steps of the trace


ssl/ssl_cert.c:466:11: invalidation part of the trace starts here
464.       X509_NAME *name;
465.   
466.       ret = sk_X509_NAME_new_null();
                 ^
467.       if (ret == NULL) {
468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:466:11: passed as argument to `sk_X509_NAME_new_null`
  464.       X509_NAME *name;
  465.   
  466.       ret = sk_X509_NAME_new_null();
                   ^
  467.       if (ret == NULL) {
  468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:466:11: return from call to `sk_X509_NAME_new_null`
  464.       X509_NAME *name;
  465.   
  466.       ret = sk_X509_NAME_new_null();
                   ^
  467.       if (ret == NULL) {
  468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:466:5: assigned
  464.       X509_NAME *name;
  465.   
  466.       ret = sk_X509_NAME_new_null();
             ^
  467.       if (ret == NULL) {
  468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:471:10: when calling `sk_X509_NAME_reserve` here
  469.           return NULL;
  470.       }
  471.       if (!sk_X509_NAME_reserve(ret, num)) {
                  ^
  472.           sk_X509_NAME_free(ret);
  473.           return NULL;

include/openssl/x509.h:77:1: parameter `sk` of sk_X509_NAME_reserve
    75.   DEFINE_STACK_OF(X509_NAME_ENTRY)
    76.   
    77. > DEFINE_STACK_OF(X509_NAME)
    78.   
    79.   # define X509_EX_V_NETSCAPE_HACK         0x8000

include/openssl/x509.h:77:1: when calling `OPENSSL_sk_reserve` here
    75.   DEFINE_STACK_OF(X509_NAME_ENTRY)
    76.   
    77. > DEFINE_STACK_OF(X509_NAME)
    78.   
    79.   # define X509_EX_V_NETSCAPE_HACK         0x8000

crypto/stack/stack.c:206:1: parameter `st` of OPENSSL_sk_reserve
      204.   }
      205.   
      206. > int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n)
      207.   {
      208.       if (st == NULL)

crypto/stack/stack.c:213:12: when calling `sk_reserve` here
      211.       if (n < 0)
      212.           return 1;
      213.       return sk_reserve(st, n, 1);
                        ^
      214.   }
      215.   

crypto/stack/stack.c:160:1: parameter `st` of sk_reserve
        158.   
        159.   /* internal STACK storage allocation */
        160. > static int sk_reserve(OPENSSL_STACK *st, int n, int exact)
        161.   {
        162.       const void **tmpdata;

crypto/stack/stack.c:197:15: when calling `CRYPTO_realloc` here
        195.       }
        196.   
        197.       tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);
                             ^
        198.       if (tmpdata == NULL)
        199.           return 0;

crypto/mem.c:228:1: parameter `str` of CRYPTO_realloc
          226.   }
          227.   
          228. > void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
          229.   {
          230.       INCREMENT(realloc_count);

crypto/mem.c:239:9: when calling `CRYPTO_free` here
          237.   
          238.       if (num == 0) {
          239.           CRYPTO_free(str, file, line);
                         ^
          240.           return NULL;
          241.       }

crypto/mem.c:286:1: parameter `str` of CRYPTO_free
            284.   }
            285.   
            286. > void CRYPTO_free(void *str, const char *file, int line)
            287.   {
            288.       INCREMENT(free_count);

crypto/mem.c:303:5: was invalidated by call to `free()`
            301.       }
            302.   #else
            303.       free(str);
                       ^
            304.   #endif
            305.   }

ssl/ssl_cert.c:466:11: use-after-lifetime part of the trace starts here
464.       X509_NAME *name;
465.   
466.       ret = sk_X509_NAME_new_null();
                 ^
467.       if (ret == NULL) {
468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:466:11: passed as argument to `sk_X509_NAME_new_null`
  464.       X509_NAME *name;
  465.   
  466.       ret = sk_X509_NAME_new_null();
                   ^
  467.       if (ret == NULL) {
  468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:466:11: return from call to `sk_X509_NAME_new_null`
  464.       X509_NAME *name;
  465.   
  466.       ret = sk_X509_NAME_new_null();
                   ^
  467.       if (ret == NULL) {
  468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:466:5: assigned
  464.       X509_NAME *name;
  465.   
  466.       ret = sk_X509_NAME_new_null();
             ^
  467.       if (ret == NULL) {
  468.           SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);

ssl/ssl_cert.c:472:9: when calling `sk_X509_NAME_free` here
  470.       }
  471.       if (!sk_X509_NAME_reserve(ret, num)) {
  472.           sk_X509_NAME_free(ret);
                 ^
  473.           return NULL;
  474.       }

crypto/mem.c:286:1: parameter `str` of CRYPTO_free
    284.   }
    285.   
    286. > void CRYPTO_free(void *str, const char *file, int line)
    287.   {
    288.       INCREMENT(free_count);

crypto/mem.c:303:5: invalid access occurs here
    301.       }
    302.   #else
    303.       free(str);
               ^
    304.   #endif
    305.   }

void CRYPTO_free(void *str, const char *file, int line)
{
    INCREMENT(free_count);
    if (free_impl != NULL && free_impl != &CRYPTO_free) {
        free_impl(str, file, line);
        return;
    }
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
    if (call_malloc_debug) {
        CRYPTO_mem_debug_free(str, 0, file, line);
        free(str);
        CRYPTO_mem_debug_free(str, 1, file, line);
    } else {
        free(str);
    }
#else
    free(str);
#endif
}
['STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk)\n{\n    int i;\n    const int num = sk_X509_NAME_num(sk);\n    STACK_OF(X509_NAME) *ret;\n    X509_NAME *name;\n    ret = sk_X509_NAME_new_null();\n    if (ret == NULL) {\n        SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    if (!sk_X509_NAME_reserve(ret, num)) {\n        sk_X509_NAME_free(ret);\n        return NULL;\n    }\n    for (i = 0; i < num; i++) {\n        name = X509_NAME_dup(sk_X509_NAME_value(sk, i));\n        if (name == NULL) {\n            SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE);\n            sk_X509_NAME_pop_free(ret, X509_NAME_free);\n            return NULL;\n        }\n        sk_X509_NAME_push(ret, name);\n    }\n    return ret;\n}', 'int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n)\n{\n    if (st == NULL)\n        return 0;\n    if (n < 0)\n        return 1;\n    return sk_reserve(st, n, 1);\n}', 'static int sk_reserve(OPENSSL_STACK *st, int n, int exact)\n{\n    const void **tmpdata;\n    int num_alloc;\n    if (n > max_nodes - st->num)\n        return 0;\n    num_alloc = st->num + n;\n    if (num_alloc < min_nodes)\n        num_alloc = min_nodes;\n    if (st->data == NULL) {\n        st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc);\n        if (st->data == NULL)\n            return 0;\n        st->num_alloc = num_alloc;\n        return 1;\n    }\n    if (!exact) {\n        if (num_alloc <= st->num_alloc)\n            return 1;\n        num_alloc = compute_growth(num_alloc, st->num_alloc);\n        if (num_alloc == 0)\n            return 0;\n    } else if (num_alloc == st->num_alloc) {\n        return 1;\n    }\n    tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);\n    if (tmpdata == NULL)\n        return 0;\n    st->data = tmpdata;\n    st->num_alloc = num_alloc;\n    return 1;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    INCREMENT(realloc_count);\n    if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n        return realloc_impl(str, num, file, line);\n    FAILTEST();\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str, file, line);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    (void)(file); (void)(line);\n#endif\n    return realloc(str, num);\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}']