crypto/x509v3/v3nametest.c:271: error: NULL_DEREFERENCE
  pointer `name` last assigned on line 269 could be null and is dereferenced by call to `memcpy()` at line 271, column 3.
Showing all 8 steps of the trace


crypto/x509v3/v3nametest.c:261:1: start of procedure run_cert()
259.   	}
260.   
261. > static void run_cert(X509 *crt, const char *nameincert,
262.   		     const struct set_name_fn *fn)
263.   	{

crypto/x509v3/v3nametest.c:264:2: 
262.   		     const struct set_name_fn *fn)
263.   	{
264. > 	const char *const *pname = names;
265.   	while (*pname)
266.   		{

crypto/x509v3/v3nametest.c:265:9: Loop condition is true. Entering loop body
263.   	{
264.   	const char *const *pname = names;
265.   	while (*pname)
               ^
266.   		{
267.   		int samename = strcasecmp(nameincert, *pname) == 0;

crypto/x509v3/v3nametest.c:267:18: Condition is false
265.   	while (*pname)
266.   		{
267.   		int samename = strcasecmp(nameincert, *pname) == 0;
                        ^
268.   		size_t namelen = strlen(*pname);
269.   		char *name = malloc(namelen);

crypto/x509v3/v3nametest.c:267:3: 
265.   	while (*pname)
266.   		{
267. > 		int samename = strcasecmp(nameincert, *pname) == 0;
268.   		size_t namelen = strlen(*pname);
269.   		char *name = malloc(namelen);

crypto/x509v3/v3nametest.c:268:3: 
266.   		{
267.   		int samename = strcasecmp(nameincert, *pname) == 0;
268. > 		size_t namelen = strlen(*pname);
269.   		char *name = malloc(namelen);
270.   		int match, ret;

crypto/x509v3/v3nametest.c:269:3: 
267.   		int samename = strcasecmp(nameincert, *pname) == 0;
268.   		size_t namelen = strlen(*pname);
269. > 		char *name = malloc(namelen);
270.   		int match, ret;
271.   		memcpy(name, *pname, namelen);

crypto/x509v3/v3nametest.c:271:3: 
269.   		char *name = malloc(namelen);
270.   		int match, ret;
271. > 		memcpy(name, *pname, namelen);
272.   
273.   		ret = X509_check_host(crt, (const unsigned char *)name,

static void run_cert(X509 *crt, const char *nameincert,
		     const struct set_name_fn *fn)
	{
	const char *const *pname = names;
	while (*pname)
		{
		int samename = strcasecmp(nameincert, *pname) == 0;
		size_t namelen = strlen(*pname);
		char *name = malloc(namelen);
		int match, ret;
		memcpy(name, *pname, namelen);
		ret = X509_check_host(crt, (const unsigned char *)name,
				      namelen, 0);
		match = -1;
		if (fn->host)
			{
			if (ret && !samename)
				match = 1;
			if (!ret && samename)
				match = 0;
			}
		else if (ret)
			match = 1;
		check_message(fn, "host", nameincert, match, *pname);
		ret = X509_check_host(crt, (const unsigned char *)name,
				      namelen, X509_CHECK_FLAG_NO_WILDCARDS);
		match = -1;
		if (fn->host)
			{
			if (ret && !samename)
				match = 1;
			if (!ret && samename)
				match = 0;
			}
		else if (ret)
			match = 1;
		check_message(fn, "host-no-wildcards",
			      nameincert, match, *pname);
		ret = X509_check_email(crt, (const unsigned char *)name,
				       namelen, 0);
		match = -1;
		if (fn->email)
			{
			if (ret && !samename)
				match = 1;
			if (!ret && samename && strchr(nameincert, '@') != NULL)
				match = 0;
			}
		else if (ret)
			match = 1;
		check_message(fn, "email", nameincert, match, *pname);
		++pname;
		free(name);
		}
	}
['static void run_cert(X509 *crt, const char *nameincert,\n\t\t     const struct set_name_fn *fn)\n\t{\n\tconst char *const *pname = names;\n\twhile (*pname)\n\t\t{\n\t\tint samename = strcasecmp(nameincert, *pname) == 0;\n\t\tsize_t namelen = strlen(*pname);\n\t\tchar *name = malloc(namelen);\n\t\tint match, ret;\n\t\tmemcpy(name, *pname, namelen);\n\t\tret = X509_check_host(crt, (const unsigned char *)name,\n\t\t\t\t      namelen, 0);\n\t\tmatch = -1;\n\t\tif (fn->host)\n\t\t\t{\n\t\t\tif (ret && !samename)\n\t\t\t\tmatch = 1;\n\t\t\tif (!ret && samename)\n\t\t\t\tmatch = 0;\n\t\t\t}\n\t\telse if (ret)\n\t\t\tmatch = 1;\n\t\tcheck_message(fn, "host", nameincert, match, *pname);\n\t\tret = X509_check_host(crt, (const unsigned char *)name,\n\t\t\t\t      namelen, X509_CHECK_FLAG_NO_WILDCARDS);\n\t\tmatch = -1;\n\t\tif (fn->host)\n\t\t\t{\n\t\t\tif (ret && !samename)\n\t\t\t\tmatch = 1;\n\t\t\tif (!ret && samename)\n\t\t\t\tmatch = 0;\n\t\t\t}\n\t\telse if (ret)\n\t\t\tmatch = 1;\n\t\tcheck_message(fn, "host-no-wildcards",\n\t\t\t      nameincert, match, *pname);\n\t\tret = X509_check_email(crt, (const unsigned char *)name,\n\t\t\t\t       namelen, 0);\n\t\tmatch = -1;\n\t\tif (fn->email)\n\t\t\t{\n\t\t\tif (ret && !samename)\n\t\t\t\tmatch = 1;\n\t\t\tif (!ret && samename && strchr(nameincert, \'@\') != NULL)\n\t\t\t\tmatch = 0;\n\t\t\t}\n\t\telse if (ret)\n\t\t\tmatch = 1;\n\t\tcheck_message(fn, "email", nameincert, match, *pname);\n\t\t++pname;\n\t\tfree(name);\n\t\t}\n\t}']