crypto/x509/x509_vpm.c:122: error: USE_AFTER_FREE
  call to `sk_OPENSSL_STRING_free()` eventually accesses memory that was invalidated by call to `free()` on line 119 indirectly during the call to `sk_OPENSSL_STRING_push()`.
Showing all 22 steps of the trace


crypto/x509/x509_vpm.c:114:23: invalidation part of the trace starts here
112.   
113.       if (vpm->hosts == NULL &&
114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                             ^
115.           OPENSSL_free(copy);
116.           return 0;

crypto/x509/x509_vpm.c:114:23: passed as argument to `sk_OPENSSL_STRING_new_null`
  112.   
  113.       if (vpm->hosts == NULL &&
  114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                               ^
  115.           OPENSSL_free(copy);
  116.           return 0;

crypto/x509/x509_vpm.c:114:23: return from call to `sk_OPENSSL_STRING_new_null`
  112.   
  113.       if (vpm->hosts == NULL &&
  114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                               ^
  115.           OPENSSL_free(copy);
  116.           return 0;

crypto/x509/x509_vpm.c:114:10: assigned
  112.   
  113.       if (vpm->hosts == NULL &&
  114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                  ^
  115.           OPENSSL_free(copy);
  116.           return 0;

crypto/x509/x509_vpm.c:119:10: when calling `sk_OPENSSL_STRING_push` here
  117.       }
  118.   
  119.       if (!sk_OPENSSL_STRING_push(vpm->hosts, copy)) {
                  ^
  120.           OPENSSL_free(copy);
  121.           if (sk_OPENSSL_STRING_num(vpm->hosts) == 0) {

include/openssl/safestack.h:214:1: parameter `sk` of sk_OPENSSL_STRING_push
    212.    * dealt with in the autogenerated macros below.
    213.    */
    214. > DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
    215.   
    216.   /*

include/openssl/safestack.h:214:1: when calling `sk_push` here
    212.    * dealt with in the autogenerated macros below.
    213.    */
    214. > DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
    215.   
    216.   /*

crypto/stack/stack.c:259:1: parameter `st` of sk_push
      257.   }
      258.   
      259. > int sk_push(_STACK *st, void *data)
      260.   {
      261.       return (sk_insert(st, data, st->num));

crypto/stack/stack.c:261:13: when calling `sk_insert` here
      259.   int sk_push(_STACK *st, void *data)
      260.   {
      261.       return (sk_insert(st, data, st->num));
                         ^
      262.   }
      263.   

crypto/stack/stack.c:167:1: parameter `st` of sk_insert
        165.   }
        166.   
        167. > int sk_insert(_STACK *st, void *data, int loc)
        168.   {
        169.       char **s;

crypto/stack/stack.c:174:13: when calling `CRYPTO_realloc` here
        172.           return 0;
        173.       if (st->num_alloc <= st->num + 1) {
        174.           s = OPENSSL_realloc((char *)st->data,
                           ^
        175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
        176.           if (s == NULL)

crypto/mem.c:166:1: parameter `str` of CRYPTO_realloc
          164.   }
          165.   
          166. > void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
          167.   {
          168.       if (str == NULL)

crypto/mem.c:172:9: when calling `CRYPTO_free` here
          170.   
          171.       if (num == 0) {
          172.           CRYPTO_free(str);
                         ^
          173.           return NULL;
          174.       }

crypto/mem.c:234:1: parameter `str` of CRYPTO_free
            232.   }
            233.   
            234. > void CRYPTO_free(void *str)
            235.   {
            236.   #ifdef CRYPTO_MDEBUG

crypto/mem.c:245:5: was invalidated by call to `free()`
            243.       }
            244.   #else
            245.       free(str);
                       ^
            246.   #endif
            247.   }

crypto/x509/x509_vpm.c:114:23: use-after-lifetime part of the trace starts here
112.   
113.       if (vpm->hosts == NULL &&
114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                             ^
115.           OPENSSL_free(copy);
116.           return 0;

crypto/x509/x509_vpm.c:114:23: passed as argument to `sk_OPENSSL_STRING_new_null`
  112.   
  113.       if (vpm->hosts == NULL &&
  114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                               ^
  115.           OPENSSL_free(copy);
  116.           return 0;

crypto/x509/x509_vpm.c:114:23: return from call to `sk_OPENSSL_STRING_new_null`
  112.   
  113.       if (vpm->hosts == NULL &&
  114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                               ^
  115.           OPENSSL_free(copy);
  116.           return 0;

crypto/x509/x509_vpm.c:114:10: assigned
  112.   
  113.       if (vpm->hosts == NULL &&
  114.           (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
                  ^
  115.           OPENSSL_free(copy);
  116.           return 0;

crypto/x509/x509_vpm.c:122:13: when calling `sk_OPENSSL_STRING_free` here
  120.           OPENSSL_free(copy);
  121.           if (sk_OPENSSL_STRING_num(vpm->hosts) == 0) {
  122.               sk_OPENSSL_STRING_free(vpm->hosts);
                     ^
  123.               vpm->hosts = NULL;
  124.           }

crypto/mem.c:234:1: parameter `str` of CRYPTO_free
    232.   }
    233.   
    234. > void CRYPTO_free(void *str)
    235.   {
    236.   #ifdef CRYPTO_MDEBUG

crypto/mem.c:245:5: invalid access occurs here
    243.       }
    244.   #else
    245.       free(str);
               ^
    246.   #endif
    247.   }

void CRYPTO_free(void *str)
{
#ifdef CRYPTO_MDEBUG
    if (call_malloc_debug) {
        CRYPTO_mem_debug_free(str, 0);
        free(str);
        CRYPTO_mem_debug_free(str, 1);
    } else {
        free(str);
    }
#else
    free(str);
#endif
}
["static int int_x509_param_set_hosts(X509_VERIFY_PARAM *vpm, int mode,\n                                    const char *name, size_t namelen)\n{\n    char *copy;\n    if (namelen == 0)\n        namelen = name ? strlen(name) : 0;\n    else if (name && memchr(name, '\\0', namelen > 1 ? namelen - 1 : namelen))\n        return 0;\n    if (name && name[namelen - 1] == '\\0')\n        --namelen;\n    if (mode == SET_HOST) {\n        sk_OPENSSL_STRING_pop_free(vpm->hosts, str_free);\n        vpm->hosts = NULL;\n    }\n    if (name == NULL || namelen == 0)\n        return 1;\n    copy = OPENSSL_strndup(name, namelen);\n    if (copy == NULL)\n        return 0;\n    if (vpm->hosts == NULL &&\n        (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {\n        OPENSSL_free(copy);\n        return 0;\n    }\n    if (!sk_OPENSSL_STRING_push(vpm->hosts, copy)) {\n        OPENSSL_free(copy);\n        if (sk_OPENSSL_STRING_num(vpm->hosts) == 0) {\n            sk_OPENSSL_STRING_free(vpm->hosts);\n            vpm->hosts = NULL;\n        }\n        return 0;\n    }\n    return 1;\n}", 'DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)', 'int sk_push(_STACK *st, void *data)\n{\n    return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n    char **s;\n    if (st == NULL)\n        return 0;\n    if (st->num_alloc <= st->num + 1) {\n        s = OPENSSL_realloc((char *)st->data,\n                            (unsigned int)sizeof(char *) * st->num_alloc * 2);\n        if (s == NULL)\n            return (0);\n        st->data = s;\n        st->num_alloc *= 2;\n    }\n    if ((loc >= (int)st->num) || (loc < 0))\n        st->data[st->num] = data;\n    else {\n        memmove(&(st->data[loc + 1]),\n                &(st->data[loc]), sizeof(char *) * (st->num - loc));\n        st->data[loc] = data;\n    }\n    st->num++;\n    st->sorted = 0;\n    return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifdef 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;\n    (void)line;\n#endif\n    return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}']