crypto/x509v3/v3_scts.c:252: error: USE_AFTER_FREE
  call to `SCT_LIST_free()` eventually accesses memory that was invalidated by call to `free()` on line 185 indirectly during the call to `sk_SCT_push()`.
Showing all 22 steps of the trace


crypto/x509v3/v3_scts.c:169:15: invalidation part of the trace starts here
167.           goto done;
168.   
169.       if ((sk = sk_SCT_new_null()) == NULL)
                     ^
170.           goto done;
171.   

crypto/x509v3/v3_scts.c:169:15: passed as argument to `sk_SCT_new_null`
  167.           goto done;
  168.   
  169.       if ((sk = sk_SCT_new_null()) == NULL)
                       ^
  170.           goto done;
  171.   

crypto/x509v3/v3_scts.c:169:15: return from call to `sk_SCT_new_null`
  167.           goto done;
  168.   
  169.       if ((sk = sk_SCT_new_null()) == NULL)
                       ^
  170.           goto done;
  171.   

crypto/x509v3/v3_scts.c:169:10: assigned
  167.           goto done;
  168.   
  169.       if ((sk = sk_SCT_new_null()) == NULL)
                  ^
  170.           goto done;
  171.   

crypto/x509v3/v3_scts.c:185:14: when calling `sk_SCT_push` here
  183.           if (sct == NULL)
  184.               goto err;
  185.           if (!sk_SCT_push(sk, sct)) {
                      ^
  186.               OPENSSL_free(sct);
  187.               goto err;

crypto/include/internal/ct_int.h:117:1: parameter `sk` of sk_SCT_push
    115.   } SCT;
    116.   
    117. > DEFINE_STACK_OF(SCT)
    118.   
    119.   /*

crypto/include/internal/ct_int.h:117:1: when calling `sk_push` here
    115.   } SCT;
    116.   
    117. > DEFINE_STACK_OF(SCT)
    118.   
    119.   /*

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.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

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

crypto/x509v3/v3_scts.c:169:15: use-after-lifetime part of the trace starts here
167.           goto done;
168.   
169.       if ((sk = sk_SCT_new_null()) == NULL)
                     ^
170.           goto done;
171.   

crypto/x509v3/v3_scts.c:169:15: passed as argument to `sk_SCT_new_null`
  167.           goto done;
  168.   
  169.       if ((sk = sk_SCT_new_null()) == NULL)
                       ^
  170.           goto done;
  171.   

crypto/x509v3/v3_scts.c:169:15: return from call to `sk_SCT_new_null`
  167.           goto done;
  168.   
  169.       if ((sk = sk_SCT_new_null()) == NULL)
                       ^
  170.           goto done;
  171.   

crypto/x509v3/v3_scts.c:169:10: assigned
  167.           goto done;
  168.   
  169.       if ((sk = sk_SCT_new_null()) == NULL)
                  ^
  170.           goto done;
  171.   

crypto/x509v3/v3_scts.c:252:5: when calling `SCT_LIST_free` here
  250.   
  251.    err:
  252.       SCT_LIST_free(sk);
             ^
  253.       sk = NULL;
  254.       goto done;

crypto/mem.c:234:1: parameter `str` of CRYPTO_free
    232.   }
    233.   
    234. > void CRYPTO_free(void *str)
    235.   {
    236.   #ifndef OPENSSL_NO_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)
{
#ifndef OPENSSL_NO_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 STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a,\n                                   const unsigned char **pp, long length)\n{\n    ASN1_OCTET_STRING *oct = NULL;\n    STACK_OF(SCT) *sk = NULL;\n    SCT *sct;\n    unsigned char *p, *p2;\n    unsigned short listlen, sctlen = 0, fieldlen;\n    const unsigned char *q = *pp;\n    if (d2i_ASN1_OCTET_STRING(&oct, &q, length) == NULL)\n        return NULL;\n    if (oct->length < 2)\n        goto done;\n    p = oct->data;\n    n2s(p, listlen);\n    if (listlen != oct->length - 2)\n        goto done;\n    if ((sk = sk_SCT_new_null()) == NULL)\n        goto done;\n    while (listlen > 0) {\n        if (listlen < 2)\n            goto err;\n        n2s(p, sctlen);\n        listlen -= 2;\n        if ((sctlen < 1) || (sctlen > listlen))\n            goto err;\n        listlen -= sctlen;\n        sct = OPENSSL_malloc(sizeof(*sct));\n        if (sct == NULL)\n            goto err;\n        if (!sk_SCT_push(sk, sct)) {\n            OPENSSL_free(sct);\n            goto err;\n        }\n        sct->sct = OPENSSL_malloc(sctlen);\n        if (sct->sct == NULL)\n            goto err;\n        memcpy(sct->sct, p, sctlen);\n        sct->sct_len = sctlen;\n        p += sctlen;\n        p2 = sct->sct;\n        sct->version = *p2++;\n        if (sct->version == 0) {\n            if (sctlen < 43)\n                goto err;\n            sctlen -= 43;\n            sct->log_id = p2;\n            sct->log_id_len = 32;\n            p2 += 32;\n            n2l8(p2, sct->timestamp);\n            n2s(p2, fieldlen);\n            if (sctlen < fieldlen)\n                goto err;\n            sct->ext = p2;\n            sct->ext_len = fieldlen;\n            p2 += fieldlen;\n            sctlen -= fieldlen;\n            if (sctlen < 4)\n                goto err;\n            sctlen -= 4;\n            sct->hash_alg = *p2++;\n            sct->sig_alg = *p2++;\n            n2s(p2, fieldlen);\n            if (sctlen != fieldlen)\n                goto err;\n            sct->sig = p2;\n            sct->sig_len = fieldlen;\n        }\n    }\n done:\n    ASN1_OCTET_STRING_free(oct);\n    *pp = q;\n    return sk;\n err:\n    SCT_LIST_free(sk);\n    sk = NULL;\n    goto done;\n}', 'DEFINE_STACK_OF(SCT)', '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#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;\n    (void)line;\n#endif\n    return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_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}']