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


crypto/x509/x509_vfy.c:1721:1: start of procedure internal_verify()
1719.   }
1720.   
1721. > static int internal_verify(X509_STORE_CTX *ctx)
1722.   {
1723.       int ok = 0, n;

crypto/x509/x509_vfy.c:1723:5: 
1721.   static int internal_verify(X509_STORE_CTX *ctx)
1722.   {
1723. >     int ok = 0, n;
1724.       X509 *xs, *xi;
1725.       EVP_PKEY *pkey = NULL;

crypto/x509/x509_vfy.c:1725:5: 
1723.       int ok = 0, n;
1724.       X509 *xs, *xi;
1725. >     EVP_PKEY *pkey = NULL;
1726.       int (*cb) (int xok, X509_STORE_CTX *xctx);
1727.   

crypto/x509/x509_vfy.c:1728:5: 
1726.       int (*cb) (int xok, X509_STORE_CTX *xctx);
1727.   
1728. >     cb = ctx->verify_cb;
1729.   
1730.       n = sk_X509_num(ctx->chain);

crypto/x509/x509_vfy.c:1730:9: Condition is true
1728.       cb = ctx->verify_cb;
1729.   
1730.       n = sk_X509_num(ctx->chain);
                ^
1731.       ctx->error_depth = n - 1;
1732.       n--;

crypto/x509/x509_vfy.c:1730:5: 
1728.       cb = ctx->verify_cb;
1729.   
1730. >     n = sk_X509_num(ctx->chain);
1731.       ctx->error_depth = n - 1;
1732.       n--;

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

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

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

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

crypto/x509/x509_vfy.c:1731:5: 
1729.   
1730.       n = sk_X509_num(ctx->chain);
1731. >     ctx->error_depth = n - 1;
1732.       n--;
1733.       xi = sk_X509_value(ctx->chain, n);

crypto/x509/x509_vfy.c:1732:5: 
1730.       n = sk_X509_num(ctx->chain);
1731.       ctx->error_depth = n - 1;
1732. >     n--;
1733.       xi = sk_X509_value(ctx->chain, n);
1734.   

crypto/x509/x509_vfy.c:1733:10: Condition is true
1731.       ctx->error_depth = n - 1;
1732.       n--;
1733.       xi = sk_X509_value(ctx->chain, n);
                 ^
1734.   
1735.       if (ctx->check_issued(ctx, xi, xi))

crypto/x509/x509_vfy.c:1733:5: 
1731.       ctx->error_depth = n - 1;
1732.       n--;
1733. >     xi = sk_X509_value(ctx->chain, n);
1734.   
1735.       if (ctx->check_issued(ctx, xi, xi))

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

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

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

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

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

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

crypto/x509/x509_vfy.c:1735:9: Taking false branch
1733.       xi = sk_X509_value(ctx->chain, n);
1734.   
1735.       if (ctx->check_issued(ctx, xi, xi))
                ^
1736.           xs = xi;
1737.       else {

crypto/x509/x509_vfy.c:1738:13: Taking false branch
1736.           xs = xi;
1737.       else {
1738.           if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
                    ^
1739.               xs = xi;
1740.               goto check_cert;

crypto/x509/x509_vfy.c:1742:13: Taking false branch
1740.               goto check_cert;
1741.           }
1742.           if (n <= 0) {
                    ^
1743.               ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
1744.               ctx->current_cert = xi;

crypto/x509/x509_vfy.c:1748:13: 
1746.               goto end;
1747.           } else {
1748. >             n--;
1749.               ctx->error_depth = n;
1750.               xs = sk_X509_value(ctx->chain, n);

crypto/x509/x509_vfy.c:1749:13: 
1747.           } else {
1748.               n--;
1749. >             ctx->error_depth = n;
1750.               xs = sk_X509_value(ctx->chain, n);
1751.           }

crypto/x509/x509_vfy.c:1750:18: Condition is true
1748.               n--;
1749.               ctx->error_depth = n;
1750.               xs = sk_X509_value(ctx->chain, n);
                         ^
1751.           }
1752.       }

crypto/x509/x509_vfy.c:1750:13: 
1748.               n--;
1749.               ctx->error_depth = n;
1750. >             xs = sk_X509_value(ctx->chain, n);
1751.           }
1752.       }

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

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

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

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

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

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

crypto/x509/x509_vfy.c:1755:12: Loop condition is true. Entering loop body
1753.   
1754.   /*      ctx->error=0;  not needed */
1755.       while (n >= 0) {
                   ^
1756.           ctx->error_depth = n;
1757.   

crypto/x509/x509_vfy.c:1756:9: 
1754.   /*      ctx->error=0;  not needed */
1755.       while (n >= 0) {
1756. >         ctx->error_depth = n;
1757.   
1758.           /*

crypto/x509/x509_vfy.c:1763:14: Taking false branch
1761.            * time.
1762.            */
1763.           if (!xs->valid
                     ^
1764.               && (xs != xi
1765.                   || (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}']