crypto/x509/x509_vfy.c:1719: error: NULL_DEREFERENCE
  pointer `xs` last assigned on line 1706 could be null and is dereferenced at line 1719, column 14.
Showing all 36 steps of the trace


crypto/x509/x509_vfy.c:1677:1: start of procedure internal_verify()
1675.   }
1676.   
1677. > static int internal_verify(X509_STORE_CTX *ctx)
1678.   {
1679.       int ok = 0, n;

crypto/x509/x509_vfy.c:1679:5: 
1677.   static int internal_verify(X509_STORE_CTX *ctx)
1678.   {
1679. >     int ok = 0, n;
1680.       X509 *xs, *xi;
1681.       EVP_PKEY *pkey = NULL;

crypto/x509/x509_vfy.c:1681:5: 
1679.       int ok = 0, n;
1680.       X509 *xs, *xi;
1681. >     EVP_PKEY *pkey = NULL;
1682.       int (*cb) (int xok, X509_STORE_CTX *xctx);
1683.   

crypto/x509/x509_vfy.c:1684:5: 
1682.       int (*cb) (int xok, X509_STORE_CTX *xctx);
1683.   
1684. >     cb = ctx->verify_cb;
1685.   
1686.       n = sk_X509_num(ctx->chain);

crypto/x509/x509_vfy.c:1686:9: Condition is true
1684.       cb = ctx->verify_cb;
1685.   
1686.       n = sk_X509_num(ctx->chain);
                ^
1687.       ctx->error_depth = n - 1;
1688.       n--;

crypto/x509/x509_vfy.c:1686:5: 
1684.       cb = ctx->verify_cb;
1685.   
1686. >     n = sk_X509_num(ctx->chain);
1687.       ctx->error_depth = n - 1;
1688.       n--;

crypto/stack/stack.c:319:1: start of procedure sk_num()
  317.   }
  318.   
  319. > int sk_num(const _STACK *st)
  320.   {
  321.       if (st == NULL)

crypto/stack/stack.c:321:9: Taking false branch
  319.   int sk_num(const _STACK *st)
  320.   {
  321.       if (st == NULL)
                 ^
  322.           return -1;
  323.       return st->num;

crypto/stack/stack.c:323:5: 
  321.       if (st == NULL)
  322.           return -1;
  323. >     return st->num;
  324.   }
  325.   

crypto/stack/stack.c:324:1: return from a call to sk_num
  322.           return -1;
  323.       return st->num;
  324. > }
  325.   
  326.   void *sk_value(const _STACK *st, int i)

crypto/x509/x509_vfy.c:1687:5: 
1685.   
1686.       n = sk_X509_num(ctx->chain);
1687. >     ctx->error_depth = n - 1;
1688.       n--;
1689.       xi = sk_X509_value(ctx->chain, n);

crypto/x509/x509_vfy.c:1688:5: 
1686.       n = sk_X509_num(ctx->chain);
1687.       ctx->error_depth = n - 1;
1688. >     n--;
1689.       xi = sk_X509_value(ctx->chain, n);
1690.   

crypto/x509/x509_vfy.c:1689:10: Condition is true
1687.       ctx->error_depth = n - 1;
1688.       n--;
1689.       xi = sk_X509_value(ctx->chain, n);
                 ^
1690.   
1691.       if (ctx->check_issued(ctx, xi, xi))

crypto/x509/x509_vfy.c:1689:5: 
1687.       ctx->error_depth = n - 1;
1688.       n--;
1689. >     xi = sk_X509_value(ctx->chain, n);
1690.   
1691.       if (ctx->check_issued(ctx, xi, xi))

crypto/stack/stack.c:326:1: start of procedure sk_value()
  324.   }
  325.   
  326. > void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:328:10: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                  ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:17: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                         ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:28: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                                    ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:330:5: 
  328.       if (!st || (i < 0) || (i >= st->num))
  329.           return NULL;
  330. >     return st->data[i];
  331.   }
  332.   

crypto/stack/stack.c:331:1: return from a call to sk_value
  329.           return NULL;
  330.       return st->data[i];
  331. > }
  332.   
  333.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_vfy.c:1691:9: Taking false branch
1689.       xi = sk_X509_value(ctx->chain, n);
1690.   
1691.       if (ctx->check_issued(ctx, xi, xi))
                ^
1692.           xs = xi;
1693.       else {

crypto/x509/x509_vfy.c:1694:13: Taking false branch
1692.           xs = xi;
1693.       else {
1694.           if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
                    ^
1695.               xs = xi;
1696.               goto check_cert;

crypto/x509/x509_vfy.c:1698:13: Taking false branch
1696.               goto check_cert;
1697.           }
1698.           if (n <= 0) {
                    ^
1699.               ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
1700.               ctx->current_cert = xi;

crypto/x509/x509_vfy.c:1704:13: 
1702.               goto end;
1703.           } else {
1704. >             n--;
1705.               ctx->error_depth = n;
1706.               xs = sk_X509_value(ctx->chain, n);

crypto/x509/x509_vfy.c:1705:13: 
1703.           } else {
1704.               n--;
1705. >             ctx->error_depth = n;
1706.               xs = sk_X509_value(ctx->chain, n);
1707.           }

crypto/x509/x509_vfy.c:1706:18: Condition is true
1704.               n--;
1705.               ctx->error_depth = n;
1706.               xs = sk_X509_value(ctx->chain, n);
                         ^
1707.           }
1708.       }

crypto/x509/x509_vfy.c:1706:13: 
1704.               n--;
1705.               ctx->error_depth = n;
1706. >             xs = sk_X509_value(ctx->chain, n);
1707.           }
1708.       }

crypto/stack/stack.c:326:1: start of procedure sk_value()
  324.   }
  325.   
  326. > void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:328:10: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                  ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:17: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                         ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:28: Taking true branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                                    ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:329:9: 
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
  329. >         return NULL;
  330.       return st->data[i];
  331.   }

crypto/stack/stack.c:331:1: return from a call to sk_value
  329.           return NULL;
  330.       return st->data[i];
  331. > }
  332.   
  333.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_vfy.c:1711:12: Loop condition is true. Entering loop body
1709.   
1710.   /*      ctx->error=0;  not needed */
1711.       while (n >= 0) {
                   ^
1712.           ctx->error_depth = n;
1713.   

crypto/x509/x509_vfy.c:1712:9: 
1710.   /*      ctx->error=0;  not needed */
1711.       while (n >= 0) {
1712. >         ctx->error_depth = n;
1713.   
1714.           /*

crypto/x509/x509_vfy.c:1719:14: Taking false branch
1717.            * time.
1718.            */
1719.           if (!xs->valid
                     ^
1720.               && (xs != xi
1721.                   || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE))) {

static int internal_verify(X509_STORE_CTX *ctx)
{
    int ok = 0, n;
    X509 *xs, *xi;
    EVP_PKEY *pkey = NULL;
    int (*cb) (int xok, X509_STORE_CTX *xctx);
    cb = ctx->verify_cb;
    n = sk_X509_num(ctx->chain);
    ctx->error_depth = n - 1;
    n--;
    xi = sk_X509_value(ctx->chain, n);
    if (ctx->check_issued(ctx, xi, xi))
        xs = xi;
    else {
        if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
            xs = xi;
            goto check_cert;
        }
        if (n <= 0) {
            ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
            ctx->current_cert = xi;
            ok = cb(0, ctx);
            goto end;
        } else {
            n--;
            ctx->error_depth = n;
            xs = sk_X509_value(ctx->chain, n);
        }
    }
    while (n >= 0) {
        ctx->error_depth = n;
        if (!xs->valid
            && (xs != xi
                || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE))) {
            if ((pkey = X509_get_pubkey(xi)) == NULL) {
                ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
                ctx->current_cert = xi;
                ok = (*cb) (0, ctx);
                if (!ok)
                    goto end;
            } else if (X509_verify(xs, pkey) <= 0) {
                ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE;
                ctx->current_cert = xs;
                ok = (*cb) (0, ctx);
                if (!ok) {
                    EVP_PKEY_free(pkey);
                    goto end;
                }
            }
            EVP_PKEY_free(pkey);
            pkey = NULL;
        }
        xs->valid = 1;
 check_cert:
        ok = x509_check_cert_time(ctx, xs, 0);
        if (!ok)
            goto end;
        ctx->current_issuer = xi;
        ctx->current_cert = xs;
        ok = (*cb) (1, ctx);
        if (!ok)
            goto end;
        n--;
        if (n >= 0) {
            xi = xs;
            xs = sk_X509_value(ctx->chain, n);
        }
    }
    ok = 1;
 end:
    return ok;
}
['static int internal_verify(X509_STORE_CTX *ctx)\n{\n    int ok = 0, n;\n    X509 *xs, *xi;\n    EVP_PKEY *pkey = NULL;\n    int (*cb) (int xok, X509_STORE_CTX *xctx);\n    cb = ctx->verify_cb;\n    n = sk_X509_num(ctx->chain);\n    ctx->error_depth = n - 1;\n    n--;\n    xi = sk_X509_value(ctx->chain, n);\n    if (ctx->check_issued(ctx, xi, xi))\n        xs = xi;\n    else {\n        if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {\n            xs = xi;\n            goto check_cert;\n        }\n        if (n <= 0) {\n            ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;\n            ctx->current_cert = xi;\n            ok = cb(0, ctx);\n            goto end;\n        } else {\n            n--;\n            ctx->error_depth = n;\n            xs = sk_X509_value(ctx->chain, n);\n        }\n    }\n    while (n >= 0) {\n        ctx->error_depth = n;\n        if (!xs->valid\n            && (xs != xi\n                || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE))) {\n            if ((pkey = X509_get_pubkey(xi)) == NULL) {\n                ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;\n                ctx->current_cert = xi;\n                ok = (*cb) (0, ctx);\n                if (!ok)\n                    goto end;\n            } else if (X509_verify(xs, pkey) <= 0) {\n                ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE;\n                ctx->current_cert = xs;\n                ok = (*cb) (0, ctx);\n                if (!ok) {\n                    EVP_PKEY_free(pkey);\n                    goto end;\n                }\n            }\n            EVP_PKEY_free(pkey);\n            pkey = NULL;\n        }\n        xs->valid = 1;\n check_cert:\n        ok = x509_check_cert_time(ctx, xs, 0);\n        if (!ok)\n            goto end;\n        ctx->current_issuer = xi;\n        ctx->current_cert = xs;\n        ok = (*cb) (1, ctx);\n        if (!ok)\n            goto end;\n        n--;\n        if (n >= 0) {\n            xi = xs;\n            xs = sk_X509_value(ctx->chain, n);\n        }\n    }\n    ok = 1;\n end:\n    return ok;\n}', 'int sk_num(const _STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\n}']