crypto/pem/pvkfmt.c:662: error: NULL_DEREFERENCE
  pointer `mctx` last assigned on line 653 could be null and is dereferenced by call to `EVP_MD_CTX_free()` at line 662, column 5.
Showing all 23 steps of the trace


crypto/pem/pvkfmt.c:649:1: start of procedure derive_pvk_key()
647.   }
648.   
649. > static int derive_pvk_key(unsigned char *key,
650.                             const unsigned char *salt, unsigned int saltlen,
651.                             const unsigned char *pass, int passlen)

crypto/pem/pvkfmt.c:653:5: 
651.                             const unsigned char *pass, int passlen)
652.   {
653. >     EVP_MD_CTX *mctx = EVP_MD_CTX_new();;
654.       int rv = 1;
655.       if (mctx == NULL

crypto/evp/digest.c:153:1: start of procedure EVP_MD_CTX_new()
  151.   }
  152.   
  153. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  154.   {
  155.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:155:5: 
  153.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  154.   {
  155. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  156.   }
  157.   

crypto/mem.c:315:1: start of procedure CRYPTO_zalloc()
    313.   }
    314.   
    315. > void *CRYPTO_zalloc(int num, const char *file, int line)
    316.   {
    317.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:317:5: 
    315.   void *CRYPTO_zalloc(int num, const char *file, int line)
    316.   {
    317. >     void *ret = CRYPTO_malloc(num, file, line);
    318.   
    319.       if (ret != NULL)

crypto/mem.c:279:1: start of procedure CRYPTO_malloc()
      277.   }
      278.   
      279. > void *CRYPTO_malloc(int num, const char *file, int line)
      280.   {
      281.       void *ret = NULL;

crypto/mem.c:281:5: 
      279.   void *CRYPTO_malloc(int num, const char *file, int line)
      280.   {
      281. >     void *ret = NULL;
      282.   
      283.       if (num <= 0)

crypto/mem.c:283:9: Taking false branch
      281.       void *ret = NULL;
      282.   
      283.       if (num <= 0)
                     ^
      284.           return NULL;
      285.   

crypto/mem.c:286:9: Taking false branch
      284.           return NULL;
      285.   
      286.       if (allow_customize)
                     ^
      287.           allow_customize = 0;
      288.       if (malloc_debug_func != NULL) {

crypto/mem.c:288:9: Taking false branch
      286.       if (allow_customize)
      287.           allow_customize = 0;
      288.       if (malloc_debug_func != NULL) {
                     ^
      289.           if (allow_customize_debug)
      290.               allow_customize_debug = 0;

crypto/mem.c:293:5: Skipping __function_pointer__(): unresolved function pointer
      291.           malloc_debug_func(NULL, num, file, line, 0);
      292.       }
      293.       ret = malloc_ex_func(num, file, line);
                 ^
      294.   #ifdef LEVITTE_DEBUG_MEM
      295.       fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:297:9: Taking false branch
      295.       fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
      296.   #endif
      297.       if (malloc_debug_func != NULL)
                     ^
      298.           malloc_debug_func(ret, num, file, line, 1);
      299.   

crypto/mem.c:312:5: 
      310.   #endif
      311.   
      312. >     return ret;
      313.   }
      314.   

crypto/mem.c:313:1: return from a call to CRYPTO_malloc
      311.   
      312.       return ret;
      313. > }
      314.   
      315.   void *CRYPTO_zalloc(int num, const char *file, int line)

crypto/mem.c:319:9: Taking false branch
    317.       void *ret = CRYPTO_malloc(num, file, line);
    318.   
    319.       if (ret != NULL)
                   ^
    320.           memset(ret, 0, num);
    321.       return ret;

crypto/mem.c:321:5: 
    319.       if (ret != NULL)
    320.           memset(ret, 0, num);
    321. >     return ret;
    322.   }
    323.   

crypto/mem.c:322:1: return from a call to CRYPTO_zalloc
    320.           memset(ret, 0, num);
    321.       return ret;
    322. > }
    323.   
    324.   char *CRYPTO_strdup(const char *str, const char *file, int line)

crypto/evp/digest.c:156:1: return from a call to EVP_MD_CTX_new
  154.   {
  155.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  156. > }
  157.   
  158.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/pem/pvkfmt.c:654:5: 
652.   {
653.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();;
654. >     int rv = 1;
655.       if (mctx == NULL
656.           || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL)

crypto/pem/pvkfmt.c:655:9: Taking true branch
653.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();;
654.       int rv = 1;
655.       if (mctx == NULL
               ^
656.           || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL)
657.           || !EVP_DigestUpdate(mctx, salt, saltlen)

crypto/pem/pvkfmt.c:660:9: 
658.           || !EVP_DigestUpdate(mctx, pass, passlen)
659.           || !EVP_DigestFinal_ex(mctx, key, NULL))
660. >         rv = 0;
661.   
662.       EVP_MD_CTX_free(mctx);

crypto/pem/pvkfmt.c:662:5: 
660.           rv = 0;
661.   
662. >     EVP_MD_CTX_free(mctx);
663.       return rv;
664.   }

static int derive_pvk_key(unsigned char *key,
                          const unsigned char *salt, unsigned int saltlen,
                          const unsigned char *pass, int passlen)
{
    EVP_MD_CTX *mctx = EVP_MD_CTX_new();;
    int rv = 1;
    if (mctx == NULL
        || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL)
        || !EVP_DigestUpdate(mctx, salt, saltlen)
        || !EVP_DigestUpdate(mctx, pass, passlen)
        || !EVP_DigestFinal_ex(mctx, key, NULL))
        rv = 0;
    EVP_MD_CTX_free(mctx);
    return rv;
}
['static int derive_pvk_key(unsigned char *key,\n                          const unsigned char *salt, unsigned int saltlen,\n                          const unsigned char *pass, int passlen)\n{\n    EVP_MD_CTX *mctx = EVP_MD_CTX_new();;\n    int rv = 1;\n    if (mctx == NULL\n        || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL)\n        || !EVP_DigestUpdate(mctx, salt, saltlen)\n        || !EVP_DigestUpdate(mctx, pass, passlen)\n        || !EVP_DigestFinal_ex(mctx, key, NULL))\n        rv = 0;\n    EVP_MD_CTX_free(mctx);\n    return rv;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(int num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    if (allow_customize)\n        allow_customize = 0;\n    if (malloc_debug_func != NULL) {\n        if (allow_customize_debug)\n            allow_customize_debug = 0;\n        malloc_debug_func(NULL, num, file, line, 0);\n    }\n    ret = malloc_ex_func(num, file, line);\n#ifdef LEVITTE_DEBUG_MEM\n    fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n    if (malloc_debug_func != NULL)\n        malloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}']