apps/x509.c:1215: error: NULL_DEREFERENCE
  pointer `upkey` last assigned on line 1214 could be null and is dereferenced by call to `EVP_PKEY_copy_parameters()` at line 1215, column 2.
Showing all 19 steps of the trace


apps/x509.c:1202:1: start of procedure x509_certify()
1200.   	}
1201.   
1202. > static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
1203.   	     		X509 *x, X509 *xca, EVP_PKEY *pkey,
1204.   			STACK_OF(OPENSSL_STRING) *sigopts,

apps/x509.c:1209:2: 
1207.   			ASN1_INTEGER *sno)
1208.   	{
1209. > 	int ret=0;
1210.   	ASN1_INTEGER *bs=NULL;
1211.   	X509_STORE_CTX xsc;

apps/x509.c:1210:2: 
1208.   	{
1209.   	int ret=0;
1210. > 	ASN1_INTEGER *bs=NULL;
1211.   	X509_STORE_CTX xsc;
1212.   	EVP_PKEY *upkey;

apps/x509.c:1214:2: 
1212.   	EVP_PKEY *upkey;
1213.   
1214. > 	upkey = X509_get_pubkey(xca);
1215.   	EVP_PKEY_copy_parameters(upkey,pkey);
1216.   	EVP_PKEY_free(upkey);

crypto/x509/x509_cmp.c:300:1: start of procedure X509_get_pubkey()
  298.   	}
  299.   
  300. > EVP_PKEY *X509_get_pubkey(X509 *x)
  301.   	{
  302.   	if ((x == NULL) || (x->cert_info == NULL))

crypto/x509/x509_cmp.c:302:7: Taking false branch
  300.   EVP_PKEY *X509_get_pubkey(X509 *x)
  301.   	{
  302.   	if ((x == NULL) || (x->cert_info == NULL))
               ^
  303.   		return(NULL);
  304.   	return(X509_PUBKEY_get(x->cert_info->key));

crypto/x509/x509_cmp.c:302:22: Taking false branch
  300.   EVP_PKEY *X509_get_pubkey(X509 *x)
  301.   	{
  302.   	if ((x == NULL) || (x->cert_info == NULL))
                              ^
  303.   		return(NULL);
  304.   	return(X509_PUBKEY_get(x->cert_info->key));

crypto/x509/x509_cmp.c:304:2: 
  302.   	if ((x == NULL) || (x->cert_info == NULL))
  303.   		return(NULL);
  304. > 	return(X509_PUBKEY_get(x->cert_info->key));
  305.   	}
  306.   

crypto/asn1/x_pubkey.c:133:1: start of procedure X509_PUBKEY_get()
    131.   	}
    132.   
    133. > EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
    134.   	{
    135.   	EVP_PKEY *ret=NULL;

crypto/asn1/x_pubkey.c:135:2: 
    133.   EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
    134.   	{
    135. > 	EVP_PKEY *ret=NULL;
    136.   
    137.   	if (key == NULL) goto error;

crypto/asn1/x_pubkey.c:137:6: Taking false branch
    135.   	EVP_PKEY *ret=NULL;
    136.   
    137.   	if (key == NULL) goto error;
                ^
    138.   
    139.   	if (key->pkey != NULL)

crypto/asn1/x_pubkey.c:139:6: Taking false branch
    137.   	if (key == NULL) goto error;
    138.   
    139.   	if (key->pkey != NULL)
                ^
    140.   		{
    141.   		CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);

crypto/asn1/x_pubkey.c:145:6: Taking true branch
    143.   		}
    144.   
    145.   	if (key->public_key == NULL) goto error;
                ^
    146.   
    147.   	if ((ret = EVP_PKEY_new()) == NULL)

crypto/asn1/x_pubkey.c:191:2: 
    189.   	return ret;
    190.   
    191. > 	error:
    192.   	if (ret != NULL)
    193.   		EVP_PKEY_free(ret);

crypto/asn1/x_pubkey.c:192:6: Taking false branch
    190.   
    191.   	error:
    192.   	if (ret != NULL)
                ^
    193.   		EVP_PKEY_free(ret);
    194.   	return(NULL);

crypto/asn1/x_pubkey.c:194:2: 
    192.   	if (ret != NULL)
    193.   		EVP_PKEY_free(ret);
    194. > 	return(NULL);
    195.   	}
    196.   

crypto/asn1/x_pubkey.c:195:2: return from a call to X509_PUBKEY_get
    193.   		EVP_PKEY_free(ret);
    194.   	return(NULL);
    195.   	}
            ^
    196.   
    197.   /* Now two pseudo ASN1 routines that take an EVP_PKEY structure

crypto/x509/x509_cmp.c:305:2: return from a call to X509_get_pubkey
  303.   		return(NULL);
  304.   	return(X509_PUBKEY_get(x->cert_info->key));
  305.   	}
          ^
  306.   
  307.   ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)

apps/x509.c:1215:2: 
1213.   
1214.   	upkey = X509_get_pubkey(xca);
1215. > 	EVP_PKEY_copy_parameters(upkey,pkey);
1216.   	EVP_PKEY_free(upkey);
1217.   

static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
	     		X509 *x, X509 *xca, EVP_PKEY *pkey,
			STACK_OF(OPENSSL_STRING) *sigopts,
	  		char *serialfile, int create,
	     		int days, int clrext, CONF *conf, char *section,
			ASN1_INTEGER *sno)
	{
	int ret=0;
	ASN1_INTEGER *bs=NULL;
	X509_STORE_CTX xsc;
	EVP_PKEY *upkey;
	upkey = X509_get_pubkey(xca);
	EVP_PKEY_copy_parameters(upkey,pkey);
	EVP_PKEY_free(upkey);
	if(!X509_STORE_CTX_init(&xsc,ctx,x,NULL))
		{
		BIO_printf(bio_err,"Error initialising X509 store\n");
		goto end;
		}
	if (sno) bs = sno;
	else if (!(bs = x509_load_serial(CAfile, serialfile, create)))
		goto end;
	X509_STORE_CTX_set_cert(&xsc,x);
	X509_STORE_CTX_set_flags(&xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);
	if (!reqfile && X509_verify_cert(&xsc) <= 0)
		goto end;
	if (!X509_check_private_key(xca,pkey))
		{
		BIO_printf(bio_err,"CA certificate and CA private key do not match\n");
		goto end;
		}
	if (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end;
	if (!X509_set_serialNumber(x,bs)) goto end;
	if (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL)
		goto end;
	if (X509_time_adj_ex(X509_get_notAfter(x),days, 0, NULL) == NULL)
		goto end;
	if (clrext)
		{
		while (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);
		}
	if (conf)
		{
		X509V3_CTX ctx2;
#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL
		X509_set_version(x, force_version);
#else
		X509_set_version(x,2);
#endif
                X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);
                X509V3_set_nconf(&ctx2, conf);
                if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x)) goto end;
		}
	if (!do_X509_sign(bio_err, x, pkey, digest, sigopts))
		goto end;
	ret=1;
end:
	X509_STORE_CTX_cleanup(&xsc);
	if (!ret)
		ERR_print_errors(bio_err);
	if (!sno) ASN1_INTEGER_free(bs);
	return ret;
	}
['static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n\t     \t\tX509 *x, X509 *xca, EVP_PKEY *pkey,\n\t\t\tSTACK_OF(OPENSSL_STRING) *sigopts,\n\t  \t\tchar *serialfile, int create,\n\t     \t\tint days, int clrext, CONF *conf, char *section,\n\t\t\tASN1_INTEGER *sno)\n\t{\n\tint ret=0;\n\tASN1_INTEGER *bs=NULL;\n\tX509_STORE_CTX xsc;\n\tEVP_PKEY *upkey;\n\tupkey = X509_get_pubkey(xca);\n\tEVP_PKEY_copy_parameters(upkey,pkey);\n\tEVP_PKEY_free(upkey);\n\tif(!X509_STORE_CTX_init(&xsc,ctx,x,NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"Error initialising X509 store\\n");\n\t\tgoto end;\n\t\t}\n\tif (sno) bs = sno;\n\telse if (!(bs = x509_load_serial(CAfile, serialfile, create)))\n\t\tgoto end;\n\tX509_STORE_CTX_set_cert(&xsc,x);\n\tX509_STORE_CTX_set_flags(&xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);\n\tif (!reqfile && X509_verify_cert(&xsc) <= 0)\n\t\tgoto end;\n\tif (!X509_check_private_key(xca,pkey))\n\t\t{\n\t\tBIO_printf(bio_err,"CA certificate and CA private key do not match\\n");\n\t\tgoto end;\n\t\t}\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end;\n\tif (!X509_set_serialNumber(x,bs)) goto end;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL)\n\t\tgoto end;\n\tif (X509_time_adj_ex(X509_get_notAfter(x),days, 0, NULL) == NULL)\n\t\tgoto end;\n\tif (clrext)\n\t\t{\n\t\twhile (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);\n\t\t}\n\tif (conf)\n\t\t{\n\t\tX509V3_CTX ctx2;\n#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL\n\t\tX509_set_version(x, force_version);\n#else\n\t\tX509_set_version(x,2);\n#endif\n                X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n                X509V3_set_nconf(&ctx2, conf);\n                if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x)) goto end;\n\t\t}\n\tif (!do_X509_sign(bio_err, x, pkey, digest, sigopts))\n\t\tgoto end;\n\tret=1;\nend:\n\tX509_STORE_CTX_cleanup(&xsc);\n\tif (!ret)\n\t\tERR_print_errors(bio_err);\n\tif (!sno) ASN1_INTEGER_free(bs);\n\treturn ret;\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tif (key == NULL) goto error;\n\tif (key->pkey != NULL)\n\t\t{\n\t\tCRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\t\treturn key->pkey;\n\t\t}\n\tif (key->public_key == NULL) goto error;\n\tif ((ret = EVP_PKEY_new()) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\tgoto error;\n\t\t}\n\tif (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm)))\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM);\n\t\tgoto error;\n\t\t}\n\tif (ret->ameth->pub_decode)\n\t\t{\n\t\tif (!ret->ameth->pub_decode(ret, key))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\t\t\tX509_R_PUBLIC_KEY_DECODE_ERROR);\n\t\t\tgoto error;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED);\n\t\tgoto error;\n\t\t}\n\tCRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);\n\tif (key->pkey)\n\t\t{\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);\n\t\tEVP_PKEY_free(ret);\n\t\tret = key->pkey;\n\t\t}\n\telse\n\t\t{\n\t\tkey->pkey = ret;\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);\n\t\t}\n\tCRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\treturn ret;\n\terror:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}']