apps/crl2p7.c:142: error: USE_AFTER_FREE
  call to `sk_OPENSSL_STRING_free()` eventually accesses memory that was invalidated by call to `free()` on line 141 indirectly during the call to `sk_OPENSSL_STRING_push()`.
Showing all 22 steps of the trace


apps/crl2p7.c:139:32: invalidation part of the trace starts here
137.           case OPT_CERTFILE:
138.               if ((certflst == NULL)
139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                                      ^
140.                   goto end;
141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:139:32: passed as argument to `sk_OPENSSL_STRING_new_null`
  137.           case OPT_CERTFILE:
  138.               if ((certflst == NULL)
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                                        ^
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:139:32: return from call to `sk_OPENSSL_STRING_new_null`
  137.           case OPT_CERTFILE:
  138.               if ((certflst == NULL)
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                                        ^
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:139:21: assigned
  137.           case OPT_CERTFILE:
  138.               if ((certflst == NULL)
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                             ^
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:141:18: when calling `sk_OPENSSL_STRING_push` here
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {
                          ^
  142.                   sk_OPENSSL_STRING_free(certflst);
  143.                   goto end;

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.   #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.   }

apps/crl2p7.c:139:32: use-after-lifetime part of the trace starts here
137.           case OPT_CERTFILE:
138.               if ((certflst == NULL)
139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                                      ^
140.                   goto end;
141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:139:32: passed as argument to `sk_OPENSSL_STRING_new_null`
  137.           case OPT_CERTFILE:
  138.               if ((certflst == NULL)
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                                        ^
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:139:32: return from call to `sk_OPENSSL_STRING_new_null`
  137.           case OPT_CERTFILE:
  138.               if ((certflst == NULL)
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                                        ^
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:139:21: assigned
  137.           case OPT_CERTFILE:
  138.               if ((certflst == NULL)
  139.                   && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
                             ^
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {

apps/crl2p7.c:142:17: when calling `sk_OPENSSL_STRING_free` here
  140.                   goto end;
  141.               if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {
  142.                   sk_OPENSSL_STRING_free(certflst);
                         ^
  143.                   goto end;
  144.               }

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
}
['int crl2pkcs7_main(int argc, char **argv)\n{\n    BIO *in = NULL, *out = NULL;\n    PKCS7 *p7 = NULL;\n    PKCS7_SIGNED *p7s = NULL;\n    STACK_OF(OPENSSL_STRING) *certflst = NULL;\n    STACK_OF(X509) *cert_stack = NULL;\n    STACK_OF(X509_CRL) *crl_stack = NULL;\n    X509_CRL *crl = NULL;\n    char *infile = NULL, *outfile = NULL, *prog, *certfile;\n    int i = 0, informat = FORMAT_PEM, outformat = FORMAT_PEM, ret = 1, nocrl =\n        0;\n    OPTION_CHOICE o;\n    prog = opt_init(argc, argv, crl2pkcs7_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(crl2pkcs7_options);\n            ret = 0;\n            goto end;\n        case OPT_INFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))\n                goto opthelp;\n            break;\n        case OPT_OUTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n                goto opthelp;\n            break;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_NOCRL:\n            nocrl = 1;\n            break;\n        case OPT_CERTFILE:\n            if ((certflst == NULL)\n                && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)\n                goto end;\n            if (!sk_OPENSSL_STRING_push(certflst, opt_arg())) {\n                sk_OPENSSL_STRING_free(certflst);\n                goto end;\n            }\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (!nocrl) {\n        in = bio_open_default(infile, \'r\', informat);\n        if (in == NULL)\n            goto end;\n        if (informat == FORMAT_ASN1)\n            crl = d2i_X509_CRL_bio(in, NULL);\n        else if (informat == FORMAT_PEM)\n            crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);\n        if (crl == NULL) {\n            BIO_printf(bio_err, "unable to load CRL\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if ((p7 = PKCS7_new()) == NULL)\n        goto end;\n    if ((p7s = PKCS7_SIGNED_new()) == NULL)\n        goto end;\n    p7->type = OBJ_nid2obj(NID_pkcs7_signed);\n    p7->d.sign = p7s;\n    p7s->contents->type = OBJ_nid2obj(NID_pkcs7_data);\n    if (!ASN1_INTEGER_set(p7s->version, 1))\n        goto end;\n    if ((crl_stack = sk_X509_CRL_new_null()) == NULL)\n        goto end;\n    p7s->crl = crl_stack;\n    if (crl != NULL) {\n        sk_X509_CRL_push(crl_stack, crl);\n        crl = NULL;\n    }\n    if ((cert_stack = sk_X509_new_null()) == NULL)\n        goto end;\n    p7s->cert = cert_stack;\n    if (certflst)\n        for (i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) {\n            certfile = sk_OPENSSL_STRING_value(certflst, i);\n            if (add_certs_from_file(cert_stack, certfile) < 0) {\n                BIO_printf(bio_err, "error loading certificates\\n");\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        }\n    sk_OPENSSL_STRING_free(certflst);\n    out = bio_open_default(outfile, \'w\', outformat);\n    if (out == NULL)\n        goto end;\n    if (outformat == FORMAT_ASN1)\n        i = i2d_PKCS7_bio(out, p7);\n    else if (outformat == FORMAT_PEM)\n        i = PEM_write_bio_PKCS7(out, p7);\n    if (!i) {\n        BIO_printf(bio_err, "unable to write pkcs7 object\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    ret = 0;\n end:\n    BIO_free(in);\n    BIO_free_all(out);\n    PKCS7_free(p7);\n    X509_CRL_free(crl);\n    return (ret);\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#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}']