test/stack_test.c:192: error: USE_AFTER_FREE
  call to `sk_uchar_unshift()` eventually accesses memory that was invalidated by call to `free()` on line 192 indirectly during the call to `sk_uchar_unshift()`.
Showing all 24 steps of the trace


test/stack_test.c:178:26: invalidation part of the trace starts here
176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
177.       const int n = OSSL_NELEM(v);
178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
                                ^
179.       int i;
180.       int testresult = 0;

test/stack_test.c:178:26: passed as argument to `sk_uchar_new`
  176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
  177.       const int n = OSSL_NELEM(v);
  178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
                                  ^
  179.       int i;
  180.       int testresult = 0;

test/stack_test.c:178:26: return from call to `sk_uchar_new`
  176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
  177.       const int n = OSSL_NELEM(v);
  178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
                                  ^
  179.       int i;
  180.       int testresult = 0;

test/stack_test.c:178:5: assigned
  176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
  177.       const int n = OSSL_NELEM(v);
  178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
             ^
  179.       int i;
  180.       int testresult = 0;

test/stack_test.c:192:9: when calling `sk_uchar_unshift` here
  190.               goto end;
  191.           }
  192.           sk_uchar_unshift(s, v + i);
                 ^
  193.       }
  194.       if (!TEST_int_eq(sk_uchar_num(s), n))

test/stack_test.c:40:1: parameter `sk` of sk_uchar_unshift
    38.   
    39.   DEFINE_SPECIAL_STACK_OF(sint, int)
    40. > DEFINE_SPECIAL_STACK_OF_CONST(uchar, unsigned char)
    41.   DEFINE_STACK_OF(SS)
    42.   DEFINE_STACK_OF_CONST(SU)

test/stack_test.c:40:1: when calling `OPENSSL_sk_unshift` here
    38.   
    39.   DEFINE_SPECIAL_STACK_OF(sint, int)
    40. > DEFINE_SPECIAL_STACK_OF_CONST(uchar, unsigned char)
    41.   DEFINE_STACK_OF(SS)
    42.   DEFINE_STACK_OF_CONST(SU)

crypto/stack/stack.c:312:1: parameter `st` of OPENSSL_sk_unshift
      310.   }
      311.   
      312. > int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data)
      313.   {
      314.       return OPENSSL_sk_insert(st, data, 0);

crypto/stack/stack.c:314:12: when calling `OPENSSL_sk_insert` here
      312.   int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data)
      313.   {
      314.       return OPENSSL_sk_insert(st, data, 0);
                        ^
      315.   }
      316.   

crypto/stack/stack.c:216:1: parameter `st` of OPENSSL_sk_insert
        214.   }
        215.   
        216. > int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)
        217.   {
        218.       if (st == NULL || st->num == max_nodes)

crypto/stack/stack.c:221:10: when calling `sk_reserve` here
        219.           return 0;
        220.   
        221.       if (!sk_reserve(st, 1, 0))
                        ^
        222.           return 0;
        223.   

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

test/stack_test.c:178:26: use-after-lifetime part of the trace starts here
176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
177.       const int n = OSSL_NELEM(v);
178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
                                ^
179.       int i;
180.       int testresult = 0;

test/stack_test.c:178:26: passed as argument to `sk_uchar_new`
  176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
  177.       const int n = OSSL_NELEM(v);
  178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
                                  ^
  179.       int i;
  180.       int testresult = 0;

test/stack_test.c:178:26: return from call to `sk_uchar_new`
  176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
  177.       const int n = OSSL_NELEM(v);
  178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
                                  ^
  179.       int i;
  180.       int testresult = 0;

test/stack_test.c:178:5: assigned
  176.       static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 };
  177.       const int n = OSSL_NELEM(v);
  178.       STACK_OF(uchar) *s = sk_uchar_new(&uchar_compare), *r = NULL;
             ^
  179.       int i;
  180.       int testresult = 0;

test/stack_test.c:192:9: when calling `sk_uchar_unshift` here
  190.               goto end;
  191.           }
  192.           sk_uchar_unshift(s, v + i);
                 ^
  193.       }
  194.       if (!TEST_int_eq(sk_uchar_num(s), n))

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