apps/cms.c:695: error: USE_AFTER_FREE
  call to `sk_X509_push()` eventually accesses memory that was invalidated by call to `free()` on line 695 indirectly during the call to `sk_X509_push()`.
Showing all 24 steps of the trace


apps/cms.c:689:28: invalidation part of the trace starts here
687.   
688.           if (*argv && encerts == NULL)
689.               if ((encerts = sk_X509_new_null()) == NULL)
                                  ^
690.                   goto end;
691.           while (*argv) {

apps/cms.c:689:28: passed as argument to `sk_X509_new_null`
  687.   
  688.           if (*argv && encerts == NULL)
  689.               if ((encerts = sk_X509_new_null()) == NULL)
                                    ^
  690.                   goto end;
  691.           while (*argv) {

apps/cms.c:689:28: return from call to `sk_X509_new_null`
  687.   
  688.           if (*argv && encerts == NULL)
  689.               if ((encerts = sk_X509_new_null()) == NULL)
                                    ^
  690.                   goto end;
  691.           while (*argv) {

apps/cms.c:689:18: assigned
  687.   
  688.           if (*argv && encerts == NULL)
  689.               if ((encerts = sk_X509_new_null()) == NULL)
                          ^
  690.                   goto end;
  691.           while (*argv) {

apps/cms.c:695:13: when calling `sk_X509_push` here
  693.                                     "recipient certificate file")) == NULL)
  694.                   goto end;
  695.               sk_X509_push(encerts, cert);
                     ^
  696.               cert = NULL;
  697.               argv++;

include/openssl/x509.h:99:1: parameter `sk` of sk_X509_push
    97.   typedef struct x509_cinf_st X509_CINF;
    98.   
    99. > DEFINE_STACK_OF(X509)
    100.   
    101.   /* This is used for a table of trust checking functions */

include/openssl/x509.h:99:1: when calling `OPENSSL_sk_push` here
    97.   typedef struct x509_cinf_st X509_CINF;
    98.   
    99. > DEFINE_STACK_OF(X509)
    100.   
    101.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:325:1: parameter `st` of OPENSSL_sk_push
      323.   }
      324.   
      325. > int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)
      326.   {
      327.       if (st == NULL)

crypto/stack/stack.c:329:12: when calling `OPENSSL_sk_insert` here
      327.       if (st == NULL)
      328.           return -1;
      329.       return OPENSSL_sk_insert(st, data, st->num);
                        ^
      330.   }
      331.   

crypto/stack/stack.c:236:1: parameter `st` of OPENSSL_sk_insert
        234.   }
        235.   
        236. > int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)
        237.   {
        238.       if (st == NULL || st->num == max_nodes)

crypto/stack/stack.c:241:10: when calling `sk_reserve` here
        239.           return 0;
        240.   
        241.       if (!sk_reserve(st, 1, 0))
                        ^
        242.           return 0;
        243.   

crypto/stack/stack.c:159:1: parameter `st` of sk_reserve
          157.   
          158.   /* internal STACK storage allocation */
          159. > static int sk_reserve(OPENSSL_STACK *st, int n, int exact)
          160.   {
          161.       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:238:1: parameter `str` of CRYPTO_realloc
            236.   }
            237.   
            238. > void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
            239.   {
            240.       INCREMENT(realloc_count);

crypto/mem.c:249:9: when calling `CRYPTO_free` here
            247.   
            248.       if (num == 0) {
            249.           CRYPTO_free(str, file, line);
                           ^
            250.           return NULL;
            251.       }

crypto/mem.c:295:1: parameter `str` of CRYPTO_free
              293.   }
              294.   
              295. > void CRYPTO_free(void *str, const char *file, int line)
              296.   {
              297.       INCREMENT(free_count);

crypto/mem.c:312:5: was invalidated by call to `free()`
              310.       }
              311.   #else
              312.       free(str);
                         ^
              313.   #endif
              314.   }

apps/cms.c:689:28: use-after-lifetime part of the trace starts here
687.   
688.           if (*argv && encerts == NULL)
689.               if ((encerts = sk_X509_new_null()) == NULL)
                                  ^
690.                   goto end;
691.           while (*argv) {

apps/cms.c:689:28: passed as argument to `sk_X509_new_null`
  687.   
  688.           if (*argv && encerts == NULL)
  689.               if ((encerts = sk_X509_new_null()) == NULL)
                                    ^
  690.                   goto end;
  691.           while (*argv) {

apps/cms.c:689:28: return from call to `sk_X509_new_null`
  687.   
  688.           if (*argv && encerts == NULL)
  689.               if ((encerts = sk_X509_new_null()) == NULL)
                                    ^
  690.                   goto end;
  691.           while (*argv) {

apps/cms.c:689:18: assigned
  687.   
  688.           if (*argv && encerts == NULL)
  689.               if ((encerts = sk_X509_new_null()) == NULL)
                          ^
  690.                   goto end;
  691.           while (*argv) {

apps/cms.c:695:13: when calling `sk_X509_push` here
  693.                                     "recipient certificate file")) == NULL)
  694.                   goto end;
  695.               sk_X509_push(encerts, cert);
                     ^
  696.               cert = NULL;
  697.               argv++;

crypto/mem.c:295:1: parameter `str` of CRYPTO_free
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:312:5: invalid access occurs here
    310.       }
    311.   #else
    312.       free(str);
               ^
    313.   #endif
    314.   }
