engines/ccgost/gost_pmeth.c:109: error: NULL_DEREFERENCE
  pointer `pctx->shared_ukm` last assigned on line 108 could be null and is dereferenced by call to `memcpy()` at line 109, column 4.
Showing all 24 steps of the trace


engines/ccgost/gost_pmeth.c:72:1: start of procedure pkey_gost_ctrl()
70.   
71.   /* --------------------- control functions  ------------------------------*/
72. > static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
73.   	{
74.   	struct gost_pmeth_data *pctx = (struct gost_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);

engines/ccgost/gost_pmeth.c:74:2: 
72.   static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
73.   	{
74. > 	struct gost_pmeth_data *pctx = (struct gost_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);
75.   	switch (type)
76.   		{

crypto/evp/pmeth_lib.c:460:1: start of procedure EVP_PKEY_CTX_get_data()
  458.   	}
  459.   
  460. > void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
  461.   	{
  462.   	return ctx->data;

crypto/evp/pmeth_lib.c:462:2: 
  460.   void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
  461.   	{
  462. > 	return ctx->data;
  463.   	}
  464.   

crypto/evp/pmeth_lib.c:463:2: return from a call to EVP_PKEY_CTX_get_data
  461.   	{
  462.   	return ctx->data;
  463.   	}
          ^
  464.   
  465.   EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)

engines/ccgost/gost_pmeth.c:75:2: 
73.   	{
74.   	struct gost_pmeth_data *pctx = (struct gost_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);
75. > 	switch (type)
76.   		{
77.   		case EVP_PKEY_CTRL_MD:

engines/ccgost/gost_pmeth.c:77:3: Switch condition is false. Skipping switch case
75.   	switch (type)
76.   		{
77.   		case EVP_PKEY_CTRL_MD:
        ^
78.   		{
79.   		if (EVP_MD_type((const EVP_MD *)p2) != NID_id_GostR3411_94)

engines/ccgost/gost_pmeth.c:89:3: Switch condition is false. Skipping switch case
87.   		break;
88.   
89.   		case EVP_PKEY_CTRL_GET_MD:
        ^
90.   		*(const EVP_MD **)p2 = pctx->md;
91.   		return 1;

engines/ccgost/gost_pmeth.c:93:3: Switch condition is false. Skipping switch case
91.   		return 1;
92.   
93.   		case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
        ^
94.   		case EVP_PKEY_CTRL_PKCS7_DECRYPT:
95.   		case EVP_PKEY_CTRL_PKCS7_SIGN:

engines/ccgost/gost_pmeth.c:94:3: Switch condition is false. Skipping switch case
92.   
93.   		case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
94.   		case EVP_PKEY_CTRL_PKCS7_DECRYPT:
        ^
95.   		case EVP_PKEY_CTRL_PKCS7_SIGN:
96.   		case EVP_PKEY_CTRL_DIGESTINIT:

engines/ccgost/gost_pmeth.c:95:3: Switch condition is false. Skipping switch case
93.   		case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
94.   		case EVP_PKEY_CTRL_PKCS7_DECRYPT:
95.   		case EVP_PKEY_CTRL_PKCS7_SIGN:
        ^
96.   		case EVP_PKEY_CTRL_DIGESTINIT:
97.   #ifndef OPENSSL_NO_CMS		

engines/ccgost/gost_pmeth.c:96:3: Switch condition is false. Skipping switch case
94.   		case EVP_PKEY_CTRL_PKCS7_DECRYPT:
95.   		case EVP_PKEY_CTRL_PKCS7_SIGN:
96.   		case EVP_PKEY_CTRL_DIGESTINIT:
        ^
97.   #ifndef OPENSSL_NO_CMS		
98.   		case EVP_PKEY_CTRL_CMS_ENCRYPT:

engines/ccgost/gost_pmeth.c:98:3: Switch condition is false. Skipping switch case
96.   		case EVP_PKEY_CTRL_DIGESTINIT:
97.   #ifndef OPENSSL_NO_CMS		
98.   		case EVP_PKEY_CTRL_CMS_ENCRYPT:
         ^
99.   		case EVP_PKEY_CTRL_CMS_DECRYPT:
100.   		case EVP_PKEY_CTRL_CMS_SIGN:

engines/ccgost/gost_pmeth.c:99:3: Switch condition is false. Skipping switch case
97.   #ifndef OPENSSL_NO_CMS		
98.   		case EVP_PKEY_CTRL_CMS_ENCRYPT:
99.   		case EVP_PKEY_CTRL_CMS_DECRYPT:
         ^
100.   		case EVP_PKEY_CTRL_CMS_SIGN:
101.   #endif		

engines/ccgost/gost_pmeth.c:100:3: Switch condition is false. Skipping switch case
98.   		case EVP_PKEY_CTRL_CMS_ENCRYPT:
99.   		case EVP_PKEY_CTRL_CMS_DECRYPT:
100.   		case EVP_PKEY_CTRL_CMS_SIGN:
         ^
101.   #endif		
102.   			return 1;

engines/ccgost/gost_pmeth.c:104:3: Switch condition is false. Skipping switch case
102.   			return 1;
103.   
104.   		case EVP_PKEY_CTRL_GOST_PARAMSET:
         ^
105.   			pctx->sign_param_nid = (int)p1;
106.   			return 1;

engines/ccgost/gost_pmeth.c:107:3: Switch condition is true. Entering switch case
105.   			pctx->sign_param_nid = (int)p1;
106.   			return 1;
107.   		case EVP_PKEY_CTRL_SET_IV:
         ^
108.   			pctx->shared_ukm=OPENSSL_malloc((int)p1);
109.   			memcpy(pctx->shared_ukm,p2,(int) p1);

engines/ccgost/gost_pmeth.c:108:4: 
106.   			return 1;
107.   		case EVP_PKEY_CTRL_SET_IV:
108. > 			pctx->shared_ukm=OPENSSL_malloc((int)p1);
109.   			memcpy(pctx->shared_ukm,p2,(int) p1);
110.   			return 1;

crypto/mem.c:297:1: start of procedure CRYPTO_malloc()
  295.   	}
  296.   
  297. > void *CRYPTO_malloc(int num, const char *file, int line)
  298.   	{
  299.   	void *ret = NULL;

crypto/mem.c:299:2: 
  297.   void *CRYPTO_malloc(int num, const char *file, int line)
  298.   	{
  299. > 	void *ret = NULL;
  300.   
  301.   	if (num <= 0) return NULL;

crypto/mem.c:301:6: Taking true branch
  299.   	void *ret = NULL;
  300.   
  301.   	if (num <= 0) return NULL;
              ^
  302.   
  303.   	if(allow_customize)

crypto/mem.c:301:16: 
  299.   	void *ret = NULL;
  300.   
  301. > 	if (num <= 0) return NULL;
  302.   
  303.   	if(allow_customize)

crypto/mem.c:329:2: return from a call to CRYPTO_malloc
  327.   
  328.   	return ret;
  329.   	}
          ^
  330.   char *CRYPTO_strdup(const char *str, const char *file, int line)
  331.   	{

engines/ccgost/gost_pmeth.c:109:4: 
107.   		case EVP_PKEY_CTRL_SET_IV:
108.   			pctx->shared_ukm=OPENSSL_malloc((int)p1);
109. > 			memcpy(pctx->shared_ukm,p2,(int) p1);
110.   			return 1;
111.   		case EVP_PKEY_CTRL_PEER_KEY:

static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
	{
	struct gost_pmeth_data *pctx = (struct gost_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);
	switch (type)
		{
		case EVP_PKEY_CTRL_MD:
		{
		if (EVP_MD_type((const EVP_MD *)p2) != NID_id_GostR3411_94)
			{
			GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE);
			return 0;
			}
		pctx->md = (EVP_MD *)p2;
		return 1;
		}
		break;
		case EVP_PKEY_CTRL_GET_MD:
		*(const EVP_MD **)p2 = pctx->md;
		return 1;
		case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
		case EVP_PKEY_CTRL_PKCS7_DECRYPT:
		case EVP_PKEY_CTRL_PKCS7_SIGN:
		case EVP_PKEY_CTRL_DIGESTINIT:
#ifndef OPENSSL_NO_CMS
		case EVP_PKEY_CTRL_CMS_ENCRYPT:
		case EVP_PKEY_CTRL_CMS_DECRYPT:
		case EVP_PKEY_CTRL_CMS_SIGN:
#endif
			return 1;
		case EVP_PKEY_CTRL_GOST_PARAMSET:
			pctx->sign_param_nid = (int)p1;
			return 1;
		case EVP_PKEY_CTRL_SET_IV:
			pctx->shared_ukm=OPENSSL_malloc((int)p1);
			memcpy(pctx->shared_ukm,p2,(int) p1);
			return 1;
		case EVP_PKEY_CTRL_PEER_KEY:
			if (p1 == 0 || p1 == 1)
				return 1;
			if (p1 == 2)
				return pctx->peer_key_used;
			if (p1 == 3)
				return (pctx->peer_key_used = 1);
			return -2;
		}
	return -2;
	}
['static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)\n\t{\n\tstruct gost_pmeth_data *pctx = (struct gost_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);\n\tswitch (type)\n\t\t{\n\t\tcase EVP_PKEY_CTRL_MD:\n\t\t{\n\t\tif (EVP_MD_type((const EVP_MD *)p2) != NID_id_GostR3411_94)\n\t\t\t{\n\t\t\tGOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE);\n\t\t\treturn 0;\n\t\t\t}\n\t\tpctx->md = (EVP_MD *)p2;\n\t\treturn 1;\n\t\t}\n\t\tbreak;\n\t\tcase EVP_PKEY_CTRL_GET_MD:\n\t\t*(const EVP_MD **)p2 = pctx->md;\n\t\treturn 1;\n\t\tcase EVP_PKEY_CTRL_PKCS7_ENCRYPT:\n\t\tcase EVP_PKEY_CTRL_PKCS7_DECRYPT:\n\t\tcase EVP_PKEY_CTRL_PKCS7_SIGN:\n\t\tcase EVP_PKEY_CTRL_DIGESTINIT:\n#ifndef OPENSSL_NO_CMS\n\t\tcase EVP_PKEY_CTRL_CMS_ENCRYPT:\n\t\tcase EVP_PKEY_CTRL_CMS_DECRYPT:\n\t\tcase EVP_PKEY_CTRL_CMS_SIGN:\n#endif\n\t\t\treturn 1;\n\t\tcase EVP_PKEY_CTRL_GOST_PARAMSET:\n\t\t\tpctx->sign_param_nid = (int)p1;\n\t\t\treturn 1;\n\t\tcase EVP_PKEY_CTRL_SET_IV:\n\t\t\tpctx->shared_ukm=OPENSSL_malloc((int)p1);\n\t\t\tmemcpy(pctx->shared_ukm,p2,(int) p1);\n\t\t\treturn 1;\n\t\tcase EVP_PKEY_CTRL_PEER_KEY:\n\t\t\tif (p1 == 0 || p1 == 1)\n\t\t\t\treturn 1;\n\t\t\tif (p1 == 2)\n\t\t\t\treturn pctx->peer_key_used;\n\t\t\tif (p1 == 3)\n\t\t\t\treturn (pctx->peer_key_used = 1);\n\t\t\treturn -2;\n\t\t}\n\treturn -2;\n\t}', 'void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)\n\t{\n\treturn ctx->data;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tif(allow_customize)\n\t\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tif(allow_customize_debug)\n\t\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n        if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}']