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


crypto/x509/x509_vfy.c:1727:1: start of procedure internal_verify()
1725.   }
1726.   
1727. > static int internal_verify(X509_STORE_CTX *ctx)
1728.   {
1729.       int ok = 0, n;

crypto/x509/x509_vfy.c:1729:5: 
1727.   static int internal_verify(X509_STORE_CTX *ctx)
1728.   {
1729. >     int ok = 0, n;
1730.       X509 *xs, *xi;
1731.       EVP_PKEY *pkey = NULL;

crypto/x509/x509_vfy.c:1731:5: 
1729.       int ok = 0, n;
1730.       X509 *xs, *xi;
1731. >     EVP_PKEY *pkey = NULL;
1732.       int (*cb) (int xok, X509_STORE_CTX *xctx);
1733.   

crypto/x509/x509_vfy.c:1734:5: 
1732.       int (*cb) (int xok, X509_STORE_CTX *xctx);
1733.   
1734. >     cb = ctx->verify_cb;
1735.   
1736.       n = sk_X509_num(ctx->chain);

crypto/x509/x509_vfy.c:1736:9: Condition is true
1734.       cb = ctx->verify_cb;
1735.   
1736.       n = sk_X509_num(ctx->chain);
                ^
1737.       ctx->error_depth = n - 1;
1738.       n--;

crypto/x509/x509_vfy.c:1736:5: 
1734.       cb = ctx->verify_cb;
1735.   
1736. >     n = sk_X509_num(ctx->chain);
1737.       ctx->error_depth = n - 1;
1738.       n--;

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

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

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

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

crypto/x509/x509_vfy.c:1737:5: 
1735.   
1736.       n = sk_X509_num(ctx->chain);
1737. >     ctx->error_depth = n - 1;
1738.       n--;
1739.       xi = sk_X509_value(ctx->chain, n);

crypto/x509/x509_vfy.c:1738:5: 
1736.       n = sk_X509_num(ctx->chain);
1737.       ctx->error_depth = n - 1;
1738. >     n--;
1739.       xi = sk_X509_value(ctx->chain, n);
1740.   

crypto/x509/x509_vfy.c:1739:10: Condition is true
1737.       ctx->error_depth = n - 1;
1738.       n--;
1739.       xi = sk_X509_value(ctx->chain, n);
                 ^
1740.   
1741.       if (ctx->check_issued(ctx, xi, xi))

crypto/x509/x509_vfy.c:1739:5: 
1737.       ctx->error_depth = n - 1;
1738.       n--;
1739. >     xi = sk_X509_value(ctx->chain, n);
1740.   
1741.       if (ctx->check_issued(ctx, xi, xi))

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

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

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

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

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

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

crypto/x509/x509_vfy.c:1741:9: Taking false branch
1739.       xi = sk_X509_value(ctx->chain, n);
1740.   
1741.       if (ctx->check_issued(ctx, xi, xi))
                ^
1742.           xs = xi;
1743.       else {

crypto/x509/x509_vfy.c:1744:13: Taking false branch
1742.           xs = xi;
1743.       else {
1744.           if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
                    ^
1745.               xs = xi;
1746.               goto check_cert;

crypto/x509/x509_vfy.c:1748:13: Taking false branch
1746.               goto check_cert;
1747.           }
1748.           if (n <= 0) {
                    ^
1749.               ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
1750.               ctx->current_cert = xi;

crypto/x509/x509_vfy.c:1754:13: 
1752.               goto end;
1753.           } else {
1754. >             n--;
1755.               ctx->error_depth = n;
1756.               xs = sk_X509_value(ctx->chain, n);

crypto/x509/x509_vfy.c:1755:13: 
1753.           } else {
1754.               n--;
1755. >             ctx->error_depth = n;
1756.               xs = sk_X509_value(ctx->chain, n);
1757.           }

crypto/x509/x509_vfy.c:1756:18: Condition is true
1754.               n--;
1755.               ctx->error_depth = n;
1756.               xs = sk_X509_value(ctx->chain, n);
                         ^
1757.           }
1758.       }

crypto/x509/x509_vfy.c:1756:13: 
1754.               n--;
1755.               ctx->error_depth = n;
1756. >             xs = sk_X509_value(ctx->chain, n);
1757.           }
1758.       }

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

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

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

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

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

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

crypto/x509/x509_vfy.c:1761:12: Loop condition is true. Entering loop body
1759.   
1760.   /*      ctx->error=0;  not needed */
1761.       while (n >= 0) {
                   ^
1762.           ctx->error_depth = n;
1763.   

crypto/x509/x509_vfy.c:1762:9: 
1760.   /*      ctx->error=0;  not needed */
1761.       while (n >= 0) {
1762. >         ctx->error_depth = n;
1763.   
1764.           /*

crypto/x509/x509_vfy.c:1769:14: Taking false branch
1767.            * time.
1768.            */
1769.           if (!xs->valid
                     ^
1770.               && (xs != xi
1771.                   || (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}']