crypto/evp/pkey_mac.c:103: error: USE_AFTER_FREE
  call to `pkey_mac_cleanup()` eventually accesses memory that was invalidated by call to `free()` on line 91 indirectly during the call to `ASN1_STRING_copy()`.
Showing all 31 steps of the trace


crypto/evp/pkey_mac.c:74:1: invalidation part of the trace starts here
72.   static void pkey_mac_cleanup(EVP_PKEY_CTX *ctx);
73.   
74. > static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
75.   {
76.       MAC_PKEY_CTX *sctx, *dctx;

crypto/evp/pkey_mac.c:74:1: parameter `dst` of pkey_mac_copy
  72.   static void pkey_mac_cleanup(EVP_PKEY_CTX *ctx);
  73.   
  74. > static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
  75.   {
  76.       MAC_PKEY_CTX *sctx, *dctx;

crypto/evp/pkey_mac.c:82:12: passed as argument to `EVP_PKEY_CTX_get_data`
  80.   
  81.       sctx = EVP_PKEY_CTX_get_data(src);
  82.       dctx = EVP_PKEY_CTX_get_data(dst);
                   ^
  83.   
  84.       if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))

crypto/evp/pkey_mac.c:82:12: return from call to `EVP_PKEY_CTX_get_data`
  80.   
  81.       sctx = EVP_PKEY_CTX_get_data(src);
  82.       dctx = EVP_PKEY_CTX_get_data(dst);
                   ^
  83.   
  84.       if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))

crypto/evp/pkey_mac.c:82:5: assigned
  80.   
  81.       sctx = EVP_PKEY_CTX_get_data(src);
  82.       dctx = EVP_PKEY_CTX_get_data(dst);
            ^
  83.   
  84.       if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))

crypto/evp/pkey_mac.c:91:14: when calling `ASN1_STRING_copy` here
  89.           dctx->raw_data.md = sctx->raw_data.md;
  90.           if (ASN1_STRING_get0_data(&sctx->raw_data.ktmp) != NULL &&
  91.               !ASN1_STRING_copy(&dctx->raw_data.ktmp, &sctx->raw_data.ktmp))
                     ^
  92.               goto err;
  93.           break;

crypto/asn1/asn1_lib.c:243:1: parameter `dst` of ASN1_STRING_copy
    241.   }
    242.   
    243. > int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
    244.   {
    245.       if (str == NULL)

crypto/asn1/asn1_lib.c:248:10: when calling `ASN1_STRING_set` here
    246.           return 0;
    247.       dst->type = str->type;
    248.       if (!ASN1_STRING_set(dst, str->data, str->length))
                    ^
    249.           return 0;
    250.       /* Copy flags but preserve embed value */

crypto/asn1/asn1_lib.c:271:1: parameter `str` of ASN1_STRING_set
      269.   }
      270.   
      271. > int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
      272.   {
      273.       unsigned char *c;

crypto/asn1/asn1_lib.c:283:9: assigned
      281.       }
      282.       if ((str->length <= len) || (str->data == NULL)) {
      283.           c = str->data;
                     ^
      284.           str->data = OPENSSL_realloc(c, len + 1);
      285.           if (str->data == NULL) {

crypto/asn1/asn1_lib.c:284:21: when calling `CRYPTO_realloc` here
      282.       if ((str->length <= len) || (str->data == NULL)) {
      283.           c = str->data;
      284.           str->data = OPENSSL_realloc(c, len + 1);
                                 ^
      285.           if (str->data == NULL) {
      286.               ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);

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

crypto/evp/pkey_mac.c:74:1: use-after-lifetime part of the trace starts here
72.   static void pkey_mac_cleanup(EVP_PKEY_CTX *ctx);
73.   
74. > static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
75.   {
76.       MAC_PKEY_CTX *sctx, *dctx;

crypto/evp/pkey_mac.c:74:1: parameter `dst` of pkey_mac_copy
  72.   static void pkey_mac_cleanup(EVP_PKEY_CTX *ctx);
  73.   
  74. > static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
  75.   {
  76.       MAC_PKEY_CTX *sctx, *dctx;

crypto/evp/pkey_mac.c:82:12: passed as argument to `EVP_PKEY_CTX_get_data`
  80.   
  81.       sctx = EVP_PKEY_CTX_get_data(src);
  82.       dctx = EVP_PKEY_CTX_get_data(dst);
                   ^
  83.   
  84.       if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))

crypto/evp/pkey_mac.c:82:12: return from call to `EVP_PKEY_CTX_get_data`
  80.   
  81.       sctx = EVP_PKEY_CTX_get_data(src);
  82.       dctx = EVP_PKEY_CTX_get_data(dst);
                   ^
  83.   
  84.       if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))

crypto/evp/pkey_mac.c:82:5: assigned
  80.   
  81.       sctx = EVP_PKEY_CTX_get_data(src);
  82.       dctx = EVP_PKEY_CTX_get_data(dst);
            ^
  83.   
  84.       if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))

crypto/evp/pkey_mac.c:91:14: passed as argument to `ASN1_STRING_copy`
  89.           dctx->raw_data.md = sctx->raw_data.md;
  90.           if (ASN1_STRING_get0_data(&sctx->raw_data.ktmp) != NULL &&
  91.               !ASN1_STRING_copy(&dctx->raw_data.ktmp, &sctx->raw_data.ktmp))
                     ^
  92.               goto err;
  93.           break;

crypto/asn1/asn1_lib.c:243:1: parameter `dst` of ASN1_STRING_copy
    241.   }
    242.   
    243. > int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
    244.   {
    245.       if (str == NULL)

crypto/asn1/asn1_lib.c:248:10: passed as argument to `ASN1_STRING_set`
    246.           return 0;
    247.       dst->type = str->type;
    248.       if (!ASN1_STRING_set(dst, str->data, str->length))
                    ^
    249.           return 0;
    250.       /* Copy flags but preserve embed value */

crypto/asn1/asn1_lib.c:271:1: parameter `str` of ASN1_STRING_set
      269.   }
      270.   
      271. > int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
      272.   {
      273.       unsigned char *c;

crypto/asn1/asn1_lib.c:283:9: assigned
      281.       }
      282.       if ((str->length <= len) || (str->data == NULL)) {
      283.           c = str->data;
                     ^
      284.           str->data = OPENSSL_realloc(c, len + 1);
      285.           if (str->data == NULL) {

crypto/asn1/asn1_lib.c:287:13: assigned
      285.           if (str->data == NULL) {
      286.               ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);
      287.               str->data = c;
                         ^
      288.               return 0;
      289.           }

crypto/asn1/asn1_lib.c:248:10: return from call to `ASN1_STRING_set`
    246.           return 0;
    247.       dst->type = str->type;
    248.       if (!ASN1_STRING_set(dst, str->data, str->length))
                    ^
    249.           return 0;
    250.       /* Copy flags but preserve embed value */

crypto/evp/pkey_mac.c:91:14: return from call to `ASN1_STRING_copy`
  89.           dctx->raw_data.md = sctx->raw_data.md;
  90.           if (ASN1_STRING_get0_data(&sctx->raw_data.ktmp) != NULL &&
  91.               !ASN1_STRING_copy(&dctx->raw_data.ktmp, &sctx->raw_data.ktmp))
                     ^
  92.               goto err;
  93.           break;

crypto/evp/pkey_mac.c:103:5: when calling `pkey_mac_cleanup` here
  101.       return 1;
  102.    err:
  103.       pkey_mac_cleanup (dst);
             ^
  104.       return 0;
  105.   }

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