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


crypto/x509/x509_vfy.c:747:1: start of procedure check_trust()
745.   }
746.   
747. > static int check_trust(X509_STORE_CTX *ctx, int num_untrusted)
748.   {
749.       int i;

crypto/x509/x509_vfy.c:750:5: 
748.   {
749.       int i;
750. >     X509 *x = NULL;
751.       X509 *mx;
752.       SSL_DANE *dane = ctx->dane;

crypto/x509/x509_vfy.c:752:5: 
750.       X509 *x = NULL;
751.       X509 *mx;
752. >     SSL_DANE *dane = ctx->dane;
753.       int num = sk_X509_num(ctx->chain);
754.       int trust;

crypto/x509/x509_vfy.c:753:5: 
751.       X509 *mx;
752.       SSL_DANE *dane = ctx->dane;
753. >     int num = sk_X509_num(ctx->chain);
754.       int trust;
755.   

include/openssl/x509.h:99:1: start of procedure sk_X509_num()
  97.   typedef struct x509_cinf_st X509_CINF;
  98.   
  99. > DEFINE_STACK_OF(X509)
  100.   
  101.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:380:1: start of procedure OPENSSL_sk_num()
    378.   }
    379.   
    380. > int OPENSSL_sk_num(const OPENSSL_STACK *st)
    381.   {
    382.       return st == NULL ? -1 : st->num;

crypto/stack/stack.c:382:12: Condition is true
    380.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
    381.   {
    382.       return st == NULL ? -1 : st->num;
                      ^
    383.   }
    384.   

crypto/stack/stack.c:382:5: 
    380.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
    381.   {
    382. >     return st == NULL ? -1 : st->num;
    383.   }
    384.   

crypto/stack/stack.c:383:1: return from a call to OPENSSL_sk_num
    381.   {
    382.       return st == NULL ? -1 : st->num;
    383. > }
    384.   
    385.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)

include/openssl/x509.h:99:1: return from a call to sk_X509_num
  97.   typedef struct x509_cinf_st X509_CINF;
  98.   
  99. > DEFINE_STACK_OF(X509)
  100.   
  101.   /* This is used for a table of trust checking functions */

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

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

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

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

crypto/x509/x509_vfy.c:788:9: Taking false branch
786.        * the chain is PKIX trusted.
787.        */
788.       if (num_untrusted < num) {
               ^
789.           if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)
790.               goto trusted;

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

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

crypto/x509/x509_vfy.c:799:9: 
797.            * for a direct trust store match.
798.            */
799. >         i = 0;
800.           x = sk_X509_value(ctx->chain, i);
801.           mx = lookup_cert_match(ctx, x);

crypto/x509/x509_vfy.c:800:9: 
798.            */
799.           i = 0;
800. >         x = sk_X509_value(ctx->chain, i);
801.           mx = lookup_cert_match(ctx, x);
802.           if (!mx)

include/openssl/x509.h:99:1: start of procedure sk_X509_value()
  97.   typedef struct x509_cinf_st X509_CINF;
  98.   
  99. > DEFINE_STACK_OF(X509)
  100.   
  101.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:385:1: start of procedure OPENSSL_sk_value()
    383.   }
    384.   
    385. > void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    386.   {
    387.       if (st == NULL || i < 0 || i >= st->num)

crypto/stack/stack.c:387:9: Taking true branch
    385.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    386.   {
    387.       if (st == NULL || i < 0 || i >= st->num)
                   ^
    388.           return NULL;
    389.       return (void *)st->data[i];

crypto/stack/stack.c:388:9: 
    386.   {
    387.       if (st == NULL || i < 0 || i >= st->num)
    388. >         return NULL;
    389.       return (void *)st->data[i];
    390.   }

crypto/stack/stack.c:390:1: return from a call to OPENSSL_sk_value
    388.           return NULL;
    389.       return (void *)st->data[i];
    390. > }
    391.   
    392.   void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data)

include/openssl/x509.h:99:1: return from a call to sk_X509_value
  97.   typedef struct x509_cinf_st X509_CINF;
  98.   
  99. > DEFINE_STACK_OF(X509)
  100.   
  101.   /* This is used for a table of trust checking functions */

crypto/x509/x509_vfy.c:801:9: 
799.           i = 0;
800.           x = sk_X509_value(ctx->chain, i);
801. >         mx = lookup_cert_match(ctx, x);
802.           if (!mx)
803.               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:99:1: start of procedure X509_get_subject_name()
    97.   #endif
    98.   
    99. > X509_NAME *X509_get_subject_name(const X509 *a)
    100.   {
    101.       return a->cert_info.subject;

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

static int check_trust(X509_STORE_CTX *ctx, int num_untrusted)
{
    int i;
    X509 *x = NULL;
    X509 *mx;
    SSL_DANE *dane = ctx->dane;
    int num = sk_X509_num(ctx->chain);
    int trust;
    if (DANETLS_HAS_TA(dane) && num_untrusted > 0 && num_untrusted < num) {
        switch (trust = check_dane_issuer(ctx, num_untrusted)) {
        case X509_TRUST_TRUSTED:
        case X509_TRUST_REJECTED:
            return trust;
        }
    }
    for (i = num_untrusted; i < num; i++) {
        x = sk_X509_value(ctx->chain, i);
        trust = X509_check_trust(x, ctx->param->trust, 0);
        if (trust == X509_TRUST_TRUSTED)
            goto trusted;
        if (trust == X509_TRUST_REJECTED)
            goto rejected;
    }
    if (num_untrusted < num) {
        if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)
            goto trusted;
        return X509_TRUST_UNTRUSTED;
    }
    if (num_untrusted == num && ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
        i = 0;
        x = sk_X509_value(ctx->chain, i);
        mx = lookup_cert_match(ctx, x);
        if (!mx)
            return X509_TRUST_UNTRUSTED;
        trust = X509_check_trust(mx, ctx->param->trust, 0);
        if (trust == X509_TRUST_REJECTED) {
            X509_free(mx);
            goto rejected;
        }
        (void) sk_X509_set(ctx->chain, 0, mx);
        X509_free(x);
        ctx->num_untrusted = 0;
        goto trusted;
    }
    return X509_TRUST_UNTRUSTED;
 rejected:
    if (!verify_cb_cert(ctx, x, i, X509_V_ERR_CERT_REJECTED))
        return X509_TRUST_REJECTED;
    return X509_TRUST_UNTRUSTED;
 trusted:
    if (!DANETLS_ENABLED(dane))
        return X509_TRUST_TRUSTED;
    if (dane->pdpth < 0)
        dane->pdpth = num_untrusted;
    if (dane->mdpth >= 0)
        return X509_TRUST_TRUSTED;
    return X509_TRUST_UNTRUSTED;
}
['static int check_trust(X509_STORE_CTX *ctx, int num_untrusted)\n{\n    int i;\n    X509 *x = NULL;\n    X509 *mx;\n    SSL_DANE *dane = ctx->dane;\n    int num = sk_X509_num(ctx->chain);\n    int trust;\n    if (DANETLS_HAS_TA(dane) && num_untrusted > 0 && num_untrusted < num) {\n        switch (trust = check_dane_issuer(ctx, num_untrusted)) {\n        case X509_TRUST_TRUSTED:\n        case X509_TRUST_REJECTED:\n            return trust;\n        }\n    }\n    for (i = num_untrusted; i < num; i++) {\n        x = sk_X509_value(ctx->chain, i);\n        trust = X509_check_trust(x, ctx->param->trust, 0);\n        if (trust == X509_TRUST_TRUSTED)\n            goto trusted;\n        if (trust == X509_TRUST_REJECTED)\n            goto rejected;\n    }\n    if (num_untrusted < num) {\n        if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)\n            goto trusted;\n        return X509_TRUST_UNTRUSTED;\n    }\n    if (num_untrusted == num && ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {\n        i = 0;\n        x = sk_X509_value(ctx->chain, i);\n        mx = lookup_cert_match(ctx, x);\n        if (!mx)\n            return X509_TRUST_UNTRUSTED;\n        trust = X509_check_trust(mx, ctx->param->trust, 0);\n        if (trust == X509_TRUST_REJECTED) {\n            X509_free(mx);\n            goto rejected;\n        }\n        (void) sk_X509_set(ctx->chain, 0, mx);\n        X509_free(x);\n        ctx->num_untrusted = 0;\n        goto trusted;\n    }\n    return X509_TRUST_UNTRUSTED;\n rejected:\n    if (!verify_cb_cert(ctx, x, i, X509_V_ERR_CERT_REJECTED))\n        return X509_TRUST_REJECTED;\n    return X509_TRUST_UNTRUSTED;\n trusted:\n    if (!DANETLS_ENABLED(dane))\n        return X509_TRUST_TRUSTED;\n    if (dane->pdpth < 0)\n        dane->pdpth = num_untrusted;\n    if (dane->mdpth >= 0)\n        return X509_TRUST_TRUSTED;\n    return X509_TRUST_UNTRUSTED;\n}', 'DEFINE_STACK_OF(X509)', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n    return st == NULL ? -1 : st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n    if (st == NULL || i < 0 || i >= st->num)\n        return NULL;\n    return (void *)st->data[i];\n}', 'static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x)\n{\n    STACK_OF(X509) *certs;\n    X509 *xtmp = NULL;\n    int i;\n    certs = ctx->lookup_certs(ctx, X509_get_subject_name(x));\n    if (certs == NULL)\n        return NULL;\n    for (i = 0; i < sk_X509_num(certs); i++) {\n        xtmp = sk_X509_value(certs, i);\n        if (!X509_cmp(xtmp, x))\n            break;\n    }\n    if (i < sk_X509_num(certs))\n        X509_up_ref(xtmp);\n    else\n        xtmp = NULL;\n    sk_X509_pop_free(certs, X509_free);\n    return xtmp;\n}', 'X509_NAME *X509_get_subject_name(const X509 *a)\n{\n    return a->cert_info.subject;\n}']