crypto/x509/x509_vfy.c:849: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 842 could be null and is dereferenced at line 849, column 9.
Showing all 17 steps of the trace


crypto/x509/x509_vfy.c:837:1: start of procedure check_cert()
835.   }
836.   
837. > static int check_cert(X509_STORE_CTX *ctx)
838.   {
839.       X509_CRL *crl = NULL, *dcrl = NULL;

crypto/x509/x509_vfy.c:839:5: 
837.   static int check_cert(X509_STORE_CTX *ctx)
838.   {
839. >     X509_CRL *crl = NULL, *dcrl = NULL;
840.       int ok = 0;
841.       int cnum = ctx->error_depth;

crypto/x509/x509_vfy.c:840:5: 
838.   {
839.       X509_CRL *crl = NULL, *dcrl = NULL;
840. >     int ok = 0;
841.       int cnum = ctx->error_depth;
842.       X509 *x = sk_X509_value(ctx->chain, cnum);

crypto/x509/x509_vfy.c:841:5: 
839.       X509_CRL *crl = NULL, *dcrl = NULL;
840.       int ok = 0;
841. >     int cnum = ctx->error_depth;
842.       X509 *x = sk_X509_value(ctx->chain, cnum);
843.   

crypto/x509/x509_vfy.c:842:5: 
840.       int ok = 0;
841.       int cnum = ctx->error_depth;
842. >     X509 *x = sk_X509_value(ctx->chain, cnum);
843.   
844.       ctx->current_cert = x;

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

crypto/stack/stack.c:284:1: start of procedure OPENSSL_sk_value()
    282.   }
    283.   
    284. > void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)

crypto/stack/stack.c:286:9: Taking false branch
    284.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)
                   ^
    287.           return NULL;
    288.       return (void *)st->data[i];

crypto/stack/stack.c:286:23: Taking true branch
    284.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)
                                 ^
    287.           return NULL;
    288.       return (void *)st->data[i];

crypto/stack/stack.c:287:9: 
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)
    287. >         return NULL;
    288.       return (void *)st->data[i];
    289.   }

crypto/stack/stack.c:289:1: return from a call to OPENSSL_sk_value
    287.           return NULL;
    288.       return (void *)st->data[i];
    289. > }
    290.   
    291.   void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data)

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

crypto/x509/x509_vfy.c:844:5: 
842.       X509 *x = sk_X509_value(ctx->chain, cnum);
843.   
844. >     ctx->current_cert = x;
845.       ctx->current_issuer = NULL;
846.       ctx->current_crl_score = 0;

crypto/x509/x509_vfy.c:845:5: 
843.   
844.       ctx->current_cert = x;
845. >     ctx->current_issuer = NULL;
846.       ctx->current_crl_score = 0;
847.       ctx->current_reasons = 0;

crypto/x509/x509_vfy.c:846:5: 
844.       ctx->current_cert = x;
845.       ctx->current_issuer = NULL;
846. >     ctx->current_crl_score = 0;
847.       ctx->current_reasons = 0;
848.   

crypto/x509/x509_vfy.c:847:5: 
845.       ctx->current_issuer = NULL;
846.       ctx->current_crl_score = 0;
847. >     ctx->current_reasons = 0;
848.   
849.       if (x->ex_flags & EXFLAG_PROXY)

crypto/x509/x509_vfy.c:849:9: 
847.       ctx->current_reasons = 0;
848.   
849. >     if (x->ex_flags & EXFLAG_PROXY)
850.           return 1;
851.   

static int check_cert(X509_STORE_CTX *ctx)
{
    X509_CRL *crl = NULL, *dcrl = NULL;
    int ok = 0;
    int cnum = ctx->error_depth;
    X509 *x = sk_X509_value(ctx->chain, cnum);
    ctx->current_cert = x;
    ctx->current_issuer = NULL;
    ctx->current_crl_score = 0;
    ctx->current_reasons = 0;
    if (x->ex_flags & EXFLAG_PROXY)
        return 1;
    while (ctx->current_reasons != CRLDP_ALL_REASONS) {
        unsigned int last_reasons = ctx->current_reasons;
        if (ctx->get_crl)
            ok = ctx->get_crl(ctx, &crl, x);
        else
            ok = get_crl_delta(ctx, &crl, &dcrl, x);
        if (!ok) {
            ok = verify_cb_crl(ctx, X509_V_ERR_UNABLE_TO_GET_CRL);
            goto done;
        }
        ctx->current_crl = crl;
        ok = ctx->check_crl(ctx, crl);
        if (!ok)
            goto done;
        if (dcrl) {
            ok = ctx->check_crl(ctx, dcrl);
            if (!ok)
                goto done;
            ok = ctx->cert_crl(ctx, dcrl, x);
            if (!ok)
                goto done;
        } else
            ok = 1;
        if (ok != 2) {
            ok = ctx->cert_crl(ctx, crl, x);
            if (!ok)
                goto done;
        }
        X509_CRL_free(crl);
        X509_CRL_free(dcrl);
        crl = NULL;
        dcrl = NULL;
        if (last_reasons == ctx->current_reasons) {
            ok = verify_cb_crl(ctx, X509_V_ERR_UNABLE_TO_GET_CRL);
            goto done;
        }
    }
 done:
    X509_CRL_free(crl);
    X509_CRL_free(dcrl);
    ctx->current_crl = NULL;
    return ok;
}
['static int check_cert(X509_STORE_CTX *ctx)\n{\n    X509_CRL *crl = NULL, *dcrl = NULL;\n    int ok = 0;\n    int cnum = ctx->error_depth;\n    X509 *x = sk_X509_value(ctx->chain, cnum);\n    ctx->current_cert = x;\n    ctx->current_issuer = NULL;\n    ctx->current_crl_score = 0;\n    ctx->current_reasons = 0;\n    if (x->ex_flags & EXFLAG_PROXY)\n        return 1;\n    while (ctx->current_reasons != CRLDP_ALL_REASONS) {\n        unsigned int last_reasons = ctx->current_reasons;\n        if (ctx->get_crl)\n            ok = ctx->get_crl(ctx, &crl, x);\n        else\n            ok = get_crl_delta(ctx, &crl, &dcrl, x);\n        if (!ok) {\n            ok = verify_cb_crl(ctx, X509_V_ERR_UNABLE_TO_GET_CRL);\n            goto done;\n        }\n        ctx->current_crl = crl;\n        ok = ctx->check_crl(ctx, crl);\n        if (!ok)\n            goto done;\n        if (dcrl) {\n            ok = ctx->check_crl(ctx, dcrl);\n            if (!ok)\n                goto done;\n            ok = ctx->cert_crl(ctx, dcrl, x);\n            if (!ok)\n                goto done;\n        } else\n            ok = 1;\n        if (ok != 2) {\n            ok = ctx->cert_crl(ctx, crl, x);\n            if (!ok)\n                goto done;\n        }\n        X509_CRL_free(crl);\n        X509_CRL_free(dcrl);\n        crl = NULL;\n        dcrl = NULL;\n        if (last_reasons == ctx->current_reasons) {\n            ok = verify_cb_crl(ctx, X509_V_ERR_UNABLE_TO_GET_CRL);\n            goto done;\n        }\n    }\n done:\n    X509_CRL_free(crl);\n    X509_CRL_free(dcrl);\n    ctx->current_crl = NULL;\n    return ok;\n}', 'DEFINE_STACK_OF(X509)', '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}']