crypto/x509/x509_cmp.c:405: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 399 could be null and is dereferenced at line 405, column 6.
Showing all 15 steps of the trace


crypto/x509/x509_cmp.c:387:1: start of procedure X509_chain_check_suiteb()
385.   	}
386.   
387. > int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,
388.   							unsigned long flags)
389.   	{

crypto/x509/x509_cmp.c:391:2: 
389.   	{
390.   	int rv, i, sign_nid;
391. > 	EVP_PKEY *pk = NULL;
392.   	unsigned long tflags;
393.   	if (!(flags & X509_V_FLAG_SUITEB_128_LOS))

crypto/x509/x509_cmp.c:393:8: Taking false branch
391.   	EVP_PKEY *pk = NULL;
392.   	unsigned long tflags;
393.   	if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
              ^
394.   		return X509_V_OK;
395.   	tflags = flags;

crypto/x509/x509_cmp.c:395:2: 
393.   	if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
394.   		return X509_V_OK;
395. > 	tflags = flags;
396.   	/* If no EE certificate passed in must be first in chain */
397.   	if (x == NULL)

crypto/x509/x509_cmp.c:397:6: Taking true branch
395.   	tflags = flags;
396.   	/* If no EE certificate passed in must be first in chain */
397.   	if (x == NULL)
            ^
398.   		{
399.   		x = sk_X509_value(chain, 0);

crypto/x509/x509_cmp.c:399:7: Condition is true
397.   	if (x == NULL)
398.   		{
399.   		x = sk_X509_value(chain, 0);
             ^
400.   		i = 1;
401.   		}

crypto/x509/x509_cmp.c:399:3: 
397.   	if (x == NULL)
398.   		{
399. > 		x = sk_X509_value(chain, 0);
400.   		i = 1;
401.   		}

crypto/stack/stack.c:300:1: start of procedure sk_value()
  298.   }
  299.   
  300. > void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;

crypto/stack/stack.c:302:6: Taking false branch
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
              ^
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:302:13: Taking false branch
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                     ^
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:302:24: Taking true branch
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                                ^
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:302:39: 
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302. > 	if(!st || (i < 0) || (i >= st->num)) return NULL;
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:304:1: return from a call to sk_value
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  303.   	return st->data[i];
  304. > }
  305.   
  306.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_cmp.c:400:3: 
398.   		{
399.   		x = sk_X509_value(chain, 0);
400. > 		i = 1;
401.   		}
402.   	else

crypto/x509/x509_cmp.c:405:6: 
403.   		i = 0;
404.   
405. > 	if (X509_get_version(x) != 2)
406.   		{
407.   		rv = X509_V_ERR_SUITE_B_INVALID_VERSION;

int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,
							unsigned long flags)
	{
	int rv, i, sign_nid;
	EVP_PKEY *pk = NULL;
	unsigned long tflags;
	if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
		return X509_V_OK;
	tflags = flags;
	if (x == NULL)
		{
		x = sk_X509_value(chain, 0);
		i = 1;
		}
	else
		i = 0;
	if (X509_get_version(x) != 2)
		{
		rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
		i = 0;
		goto end;
		}
	pk = X509_get_pubkey(x);
	rv = check_suite_b(pk, -1, &tflags);
	if (rv != X509_V_OK)
		{
		i = 0;
		goto end;
		}
	for(; i < sk_X509_num(chain); i++)
		{
		sign_nid = X509_get_signature_nid(x);
		x = sk_X509_value(chain, i);
		if (X509_get_version(x) != 2)
			{
			rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
			goto end;
			}
		EVP_PKEY_free(pk);
		pk = X509_get_pubkey(x);
		rv = check_suite_b(pk, sign_nid, &tflags);
		if (rv != X509_V_OK)
			goto end;
		}
	rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);
	end:
	if (pk)
		EVP_PKEY_free(pk);
	if (rv != X509_V_OK)
		{
		if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM
		    || rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && i)
			i--;
		if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags)
			rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;
		if (perror_depth)
			*perror_depth = i;
		}
	return rv;
	}
['int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,\n\t\t\t\t\t\t\tunsigned long flags)\n\t{\n\tint rv, i, sign_nid;\n\tEVP_PKEY *pk = NULL;\n\tunsigned long tflags;\n\tif (!(flags & X509_V_FLAG_SUITEB_128_LOS))\n\t\treturn X509_V_OK;\n\ttflags = flags;\n\tif (x == NULL)\n\t\t{\n\t\tx = sk_X509_value(chain, 0);\n\t\ti = 1;\n\t\t}\n\telse\n\t\ti = 0;\n\tif (X509_get_version(x) != 2)\n\t\t{\n\t\trv = X509_V_ERR_SUITE_B_INVALID_VERSION;\n\t\ti = 0;\n\t\tgoto end;\n\t\t}\n\tpk = X509_get_pubkey(x);\n\trv = check_suite_b(pk, -1, &tflags);\n\tif (rv != X509_V_OK)\n\t\t{\n\t\ti = 0;\n\t\tgoto end;\n\t\t}\n\tfor(; i < sk_X509_num(chain); i++)\n\t\t{\n\t\tsign_nid = X509_get_signature_nid(x);\n\t\tx = sk_X509_value(chain, i);\n\t\tif (X509_get_version(x) != 2)\n\t\t\t{\n\t\t\trv = X509_V_ERR_SUITE_B_INVALID_VERSION;\n\t\t\tgoto end;\n\t\t\t}\n\t\tEVP_PKEY_free(pk);\n\t\tpk = X509_get_pubkey(x);\n\t\trv = check_suite_b(pk, sign_nid, &tflags);\n\t\tif (rv != X509_V_OK)\n\t\t\tgoto end;\n\t\t}\n\trv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);\n\tend:\n\tif (pk)\n\t\tEVP_PKEY_free(pk);\n\tif (rv != X509_V_OK)\n\t\t{\n\t\tif ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM\n\t\t    || rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && i)\n\t\t\ti--;\n\t\tif (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags)\n\t\t\trv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;\n\t\tif (perror_depth)\n\t\t\t*perror_depth = i;\n\t\t}\n\treturn rv;\n\t}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}']