crypto/x509/x509_vfy.c:685: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 684 could be null and is dereferenced by call to `lookup_cert_match()` at line 685, column 14.
Showing all 31 steps of the trace


crypto/x509/x509_vfy.c:631:1: start of procedure check_trust()
629.   }
630.   
631. > static int check_trust(X509_STORE_CTX *ctx, int num_untrusted)
632.   {
633.       int i;

crypto/x509/x509_vfy.c:634:5: 
632.   {
633.       int i;
634. >     X509 *x = NULL;
635.       X509 *mx;
636.       SSL_DANE *dane = ctx->dane;

crypto/x509/x509_vfy.c:636:5: 
634.       X509 *x = NULL;
635.       X509 *mx;
636. >     SSL_DANE *dane = ctx->dane;
637.       int num = sk_X509_num(ctx->chain);
638.       int trust;

crypto/x509/x509_vfy.c:637:5: 
635.       X509 *mx;
636.       SSL_DANE *dane = ctx->dane;
637. >     int num = sk_X509_num(ctx->chain);
638.       int trust;
639.   

include/openssl/x509.h:104:1: start of procedure sk_X509_num()
  102.   typedef struct x509_cinf_st X509_CINF;
  103.   
  104. > DEFINE_STACK_OF(X509)
  105.   
  106.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:270:1: start of procedure OPENSSL_sk_num()
    268.   }
    269.   
    270. > int OPENSSL_sk_num(const OPENSSL_STACK *st)
    271.   {
    272.       if (st == NULL)

crypto/stack/stack.c:272:9: Taking true branch
    270.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
    271.   {
    272.       if (st == NULL)
                   ^
    273.           return -1;
    274.       return st->num;

crypto/stack/stack.c:273:9: 
    271.   {
    272.       if (st == NULL)
    273. >         return -1;
    274.       return st->num;
    275.   }

crypto/stack/stack.c:275:1: return from a call to OPENSSL_sk_num
    273.           return -1;
    274.       return st->num;
    275. > }
    276.   
    277.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)

include/openssl/x509.h:104:1: return from a call to sk_X509_num
  102.   typedef struct x509_cinf_st X509_CINF;
  103.   
  104. > DEFINE_STACK_OF(X509)
  105.   
  106.   /* This is used for a table of trust checking functions */

crypto/x509/x509_vfy.c:644:9: Taking true branch
642.        * match, we're done, otherwise we'll merely record the match depth.
643.        */
644.       if (DANETLS_HAS_TA(dane) && num_untrusted > 0 && num_untrusted < num) {
               ^
645.           switch (trust = check_dane_issuer(ctx, num_untrusted)) {
646.           case X509_TRUST_TRUSTED:

crypto/x509/x509_vfy.c:644:9: Taking false branch
642.        * match, we're done, otherwise we'll merely record the match depth.
643.        */
644.       if (DANETLS_HAS_TA(dane) && num_untrusted > 0 && num_untrusted < num) {
               ^
645.           switch (trust = check_dane_issuer(ctx, num_untrusted)) {
646.           case X509_TRUST_TRUSTED:

crypto/x509/x509_vfy.c:658:10: 
656.        * and wants to incrementally check just any added since.
657.        */
658. >     for (i = num_untrusted; i < num; i++) {
659.           x = sk_X509_value(ctx->chain, i);
660.           trust = X509_check_trust(x, ctx->param->trust, 0);

crypto/x509/x509_vfy.c:658:29: Loop condition is false. Leaving loop
656.        * and wants to incrementally check just any added since.
657.        */
658.       for (i = num_untrusted; i < num; i++) {
                                   ^
659.           x = sk_X509_value(ctx->chain, i);
660.           trust = X509_check_trust(x, ctx->param->trust, 0);

crypto/x509/x509_vfy.c:672:9: Taking false branch
670.        * the chain is PKIX trusted.
671.        */
672.       if (num_untrusted < num) {
               ^
673.           if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)
674.               goto trusted;

crypto/x509/x509_vfy.c:678:9: Taking true branch
676.       }
677.   
678.       if (num_untrusted == num && ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
               ^
679.           /*
680.            * Last-resort call with no new trusted certificates, check the leaf

crypto/x509/x509_vfy.c:678:33: Taking true branch
676.       }
677.   
678.       if (num_untrusted == num && ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
                                       ^
679.           /*
680.            * Last-resort call with no new trusted certificates, check the leaf

crypto/x509/x509_vfy.c:683:9: 
681.            * for a direct trust store match.
682.            */
683. >         i = 0;
684.           x = sk_X509_value(ctx->chain, i);
685.           mx = lookup_cert_match(ctx, x);

crypto/x509/x509_vfy.c:684:9: 
682.            */
683.           i = 0;
684. >         x = sk_X509_value(ctx->chain, i);
685.           mx = lookup_cert_match(ctx, x);
686.           if (!mx)

include/openssl/x509.h:104:1: start of procedure sk_X509_value()
  102.   typedef struct x509_cinf_st X509_CINF;
  103.   
  104. > DEFINE_STACK_OF(X509)
  105.   
  106.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:277:1: start of procedure OPENSSL_sk_value()
    275.   }
    276.   
    277. > void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    278.   {
    279.       if (st == NULL || i < 0 || i >= st->num)

crypto/stack/stack.c:279:9: Taking true branch
    277.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    278.   {
    279.       if (st == NULL || i < 0 || i >= st->num)
                   ^
    280.           return NULL;
    281.       return st->data[i];

crypto/stack/stack.c:280:9: 
    278.   {
    279.       if (st == NULL || i < 0 || i >= st->num)
    280. >         return NULL;
    281.       return st->data[i];
    282.   }

crypto/stack/stack.c:282:1: return from a call to OPENSSL_sk_value
    280.           return NULL;
    281.       return st->data[i];
    282. > }
    283.   
    284.   void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, void *value)

include/openssl/x509.h:104:1: return from a call to sk_X509_value
  102.   typedef struct x509_cinf_st X509_CINF;
  103.   
  104. > DEFINE_STACK_OF(X509)
  105.   
  106.   /* This is used for a table of trust checking functions */

crypto/x509/x509_vfy.c:685:9: 
683.           i = 0;
684.           x = sk_X509_value(ctx->chain, i);
685. >         mx = lookup_cert_match(ctx, x);
686.           if (!mx)
687.               return X509_TRUST_UNTRUSTED;

crypto/x509/x509_vfy.c:124:1: start of procedure lookup_cert_match()
  122.   /* Given a certificate try and find an exact match in the store */
  123.   
  124. > static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x)
  125.   {
  126.       STACK_OF(X509) *certs;

crypto/x509/x509_vfy.c:127:5: 
  125.   {
  126.       STACK_OF(X509) *certs;
  127. >     X509 *xtmp = NULL;
  128.       int i;
  129.       /* Lookup all certs with matching subject name */

crypto/x509/x509_vfy.c:130:5: 
  128.       int i;
  129.       /* Lookup all certs with matching subject name */
  130. >     certs = ctx->lookup_certs(ctx, X509_get_subject_name(x));
  131.       if (certs == NULL)
  132.           return NULL;

crypto/x509/x509_cmp.c:100:1: start of procedure X509_get_subject_name()
    98.   #endif
    99.   
    100. > X509_NAME *X509_get_subject_name(X509 *a)
    101.   {
    102.       return (a->cert_info.subject);

crypto/x509/x509_cmp.c:102:5: 
    100.   X509_NAME *X509_get_subject_name(X509 *a)
    101.   {
    102. >     return (a->cert_info.subject);
    103.   }
    104.   
