apps/s_server.c:637: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 636 could be null and is dereferenced by call to `X509_get1_ocsp()` at line 637, column 11.
Showing all 33 steps of the trace


apps/s_server.c:615:1: start of procedure cert_status_cb()
613.    */
614.   
615. > static int cert_status_cb(SSL *s, void *arg)
616.   {
617.       tlsextstatusctx *srctx = arg;

apps/s_server.c:617:5: 
615.   static int cert_status_cb(SSL *s, void *arg)
616.   {
617. >     tlsextstatusctx *srctx = arg;
618.       char *host = NULL, *port = NULL, *path = NULL;
619.       int use_ssl;

apps/s_server.c:618:5: 
616.   {
617.       tlsextstatusctx *srctx = arg;
618. >     char *host = NULL, *port = NULL, *path = NULL;
619.       int use_ssl;
620.       unsigned char *rspder = NULL;

apps/s_server.c:620:5: 
618.       char *host = NULL, *port = NULL, *path = NULL;
619.       int use_ssl;
620. >     unsigned char *rspder = NULL;
621.       int rspderlen;
622.       STACK_OF(OPENSSL_STRING) *aia = NULL;

apps/s_server.c:622:5: 
620.       unsigned char *rspder = NULL;
621.       int rspderlen;
622. >     STACK_OF(OPENSSL_STRING) *aia = NULL;
623.       X509 *x = NULL;
624.       X509_STORE_CTX inctx;

apps/s_server.c:623:5: 
621.       int rspderlen;
622.       STACK_OF(OPENSSL_STRING) *aia = NULL;
623. >     X509 *x = NULL;
624.       X509_STORE_CTX inctx;
625.       X509_OBJECT obj;

apps/s_server.c:626:5: 
624.       X509_STORE_CTX inctx;
625.       X509_OBJECT obj;
626. >     OCSP_REQUEST *req = NULL;
627.       OCSP_RESPONSE *resp = NULL;
628.       OCSP_CERTID *id = NULL;

apps/s_server.c:627:5: 
625.       X509_OBJECT obj;
626.       OCSP_REQUEST *req = NULL;
627. >     OCSP_RESPONSE *resp = NULL;
628.       OCSP_CERTID *id = NULL;
629.       STACK_OF(X509_EXTENSION) *exts;

apps/s_server.c:628:5: 
626.       OCSP_REQUEST *req = NULL;
627.       OCSP_RESPONSE *resp = NULL;
628. >     OCSP_CERTID *id = NULL;
629.       STACK_OF(X509_EXTENSION) *exts;
630.       int ret = SSL_TLSEXT_ERR_NOACK;

apps/s_server.c:630:5: 
628.       OCSP_CERTID *id = NULL;
629.       STACK_OF(X509_EXTENSION) *exts;
630. >     int ret = SSL_TLSEXT_ERR_NOACK;
631.       int i;
632.   

apps/s_server.c:633:9: Taking true branch
631.       int i;
632.   
633.       if (srctx->verbose)
               ^
634.           BIO_puts(bio_err, "cert_status: callback called\n");
635.       /* Build up OCSP query from server certificate */

apps/s_server.c:634:9: 
632.   
633.       if (srctx->verbose)
634. >         BIO_puts(bio_err, "cert_status: callback called\n");
635.       /* Build up OCSP query from server certificate */
636.       x = SSL_get_certificate(s);

crypto/bio/bio_lib.c:244:1: start of procedure BIO_puts()
  242.   }
  243.   
  244. > int BIO_puts(BIO *b, const char *in)
  245.   {
  246.       int i;

crypto/bio/bio_lib.c:249:10: Taking false branch
  247.       long (*cb) (BIO *, int, const char *, int, long, long);
  248.   
  249.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
                  ^
  250.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
  251.           return (-2);

crypto/bio/bio_lib.c:249:25: Taking false branch
  247.       long (*cb) (BIO *, int, const char *, int, long, long);
  248.   
  249.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
                                 ^
  250.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
  251.           return (-2);

crypto/bio/bio_lib.c:249:48: Taking false branch
  247.       long (*cb) (BIO *, int, const char *, int, long, long);
  248.   
  249.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
                                                        ^
  250.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
  251.           return (-2);

crypto/bio/bio_lib.c:254:5: 
  252.       }
  253.   
  254. >     cb = b->callback;
  255.   
  256.       if ((cb != NULL) && ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0))

crypto/bio/bio_lib.c:256:10: Taking false branch
  254.       cb = b->callback;
  255.   
  256.       if ((cb != NULL) && ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0))
                  ^
  257.           return (i);
  258.   

crypto/bio/bio_lib.c:259:10: Taking true branch
  257.           return (i);
  258.   
  259.       if (!b->init) {
                  ^
  260.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
  261.           return (-2);

crypto/bio/bio_lib.c:260:9: Skipping ERR_put_error(): empty list of specs
  258.   
  259.       if (!b->init) {
  260.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
                 ^
  261.           return (-2);
  262.       }

crypto/bio/bio_lib.c:261:9: 
  259.       if (!b->init) {
  260.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
  261. >         return (-2);
  262.       }
  263.   

crypto/bio/bio_lib.c:272:1: return from a call to BIO_puts
  270.           i = (int)cb(b, BIO_CB_PUTS | BIO_CB_RETURN, in, 0, 0L, (long)i);
  271.       return (i);
  272. > }
  273.   
  274.   int BIO_gets(BIO *b, char *in, int inl)

apps/s_server.c:636:5: 
634.           BIO_puts(bio_err, "cert_status: callback called\n");
635.       /* Build up OCSP query from server certificate */
636. >     x = SSL_get_certificate(s);
637.       aia = X509_get1_ocsp(x);
638.       if (aia) {

ssl/ssl_lib.c:3098:1: start of procedure SSL_get_certificate()
  3096.   }
  3097.   
  3098. > X509 *SSL_get_certificate(const SSL *s)
  3099.   {
  3100.       if (s->cert != NULL)

ssl/ssl_lib.c:3100:9: Taking false branch
  3098.   X509 *SSL_get_certificate(const SSL *s)
  3099.   {
  3100.       if (s->cert != NULL)
                  ^
  3101.           return (s->cert->key->x509);
  3102.       else

ssl/ssl_lib.c:3103:9: 
  3101.           return (s->cert->key->x509);
  3102.       else
  3103. >         return (NULL);
  3104.   }
  3105.   

ssl/ssl_lib.c:3104:1: return from a call to SSL_get_certificate
  3102.       else
  3103.           return (NULL);
  3104. > }
  3105.   
  3106.   EVP_PKEY *SSL_get_privatekey(const SSL *s)

apps/s_server.c:637:5: 
635.       /* Build up OCSP query from server certificate */
636.       x = SSL_get_certificate(s);
637. >     aia = X509_get1_ocsp(x);
638.       if (aia) {
639.           if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),

crypto/x509v3/v3_utl.c:534:1: start of procedure X509_get1_ocsp()
  532.   }
  533.   
  534. > STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x)
  535.   {
  536.       AUTHORITY_INFO_ACCESS *info;

crypto/x509v3/v3_utl.c:537:5: 
  535.   {
  536.       AUTHORITY_INFO_ACCESS *info;
  537. >     STACK_OF(OPENSSL_STRING) *ret = NULL;
  538.       int i;
  539.   

crypto/x509v3/v3_utl.c:540:5: 
  538.       int i;
  539.   
  540. >     info = X509_get_ext_d2i(x, NID_info_access, NULL, NULL);
  541.       if (!info)
  542.           return NULL;

crypto/x509/x509_ext.c:150:1: start of procedure X509_get_ext_d2i()
    148.   }
    149.   
    150. > void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
    151.   {
    152.       return X509V3_get_d2i(x->cert_info.extensions, nid, crit, idx);

crypto/x509/x509_ext.c:152:5: 
    150.   void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
    151.   {
    152. >     return X509V3_get_d2i(x->cert_info.extensions, nid, crit, idx);
    153.   }
    154.   

static int cert_status_cb(SSL *s, void *arg)
{
    tlsextstatusctx *srctx = arg;
    char *host = NULL, *port = NULL, *path = NULL;
    int use_ssl;
    unsigned char *rspder = NULL;
    int rspderlen;
    STACK_OF(OPENSSL_STRING) *aia = NULL;
    X509 *x = NULL;
    X509_STORE_CTX inctx;
    X509_OBJECT obj;
    OCSP_REQUEST *req = NULL;
    OCSP_RESPONSE *resp = NULL;
    OCSP_CERTID *id = NULL;
    STACK_OF(X509_EXTENSION) *exts;
    int ret = SSL_TLSEXT_ERR_NOACK;
    int i;
    if (srctx->verbose)
        BIO_puts(bio_err, "cert_status: callback called\n");
    x = SSL_get_certificate(s);
    aia = X509_get1_ocsp(x);
    if (aia) {
        if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),
                            &host, &port, &path, &use_ssl)) {
            BIO_puts(bio_err, "cert_status: can't parse AIA URL\n");
            goto err;
        }
        if (srctx->verbose)
            BIO_printf(bio_err, "cert_status: AIA URL: %s\n",
                       sk_OPENSSL_STRING_value(aia, 0));
    } else {
        if (!srctx->host) {
            BIO_puts(bio_err,
                     "cert_status: no AIA and no default responder URL\n");
            goto done;
        }
        host = srctx->host;
        path = srctx->path;
        port = srctx->port;
        use_ssl = srctx->use_ssl;
    }
    if (!X509_STORE_CTX_init(&inctx,
                             SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),
                             NULL, NULL))
        goto err;
    if (X509_STORE_get_by_subject(&inctx, X509_LU_X509,
                                  X509_get_issuer_name(x), &obj) <= 0) {
        BIO_puts(bio_err, "cert_status: Can't retrieve issuer certificate.\n");
        X509_STORE_CTX_cleanup(&inctx);
        goto done;
    }
    req = OCSP_REQUEST_new();
    if (req == NULL)
        goto err;
    id = OCSP_cert_to_id(NULL, x, obj.data.x509);
    X509_free(obj.data.x509);
    X509_STORE_CTX_cleanup(&inctx);
    if (!id)
        goto err;
    if (!OCSP_request_add0_id(req, id))
        goto err;
    id = NULL;
    SSL_get_tlsext_status_exts(s, &exts);
    for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
        X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
        if (!OCSP_REQUEST_add_ext(req, ext, -1))
            goto err;
    }
    resp = process_responder(req, host, path, port, use_ssl, NULL,
                             srctx->timeout);
    if (!resp) {
        BIO_puts(bio_err, "cert_status: error querying responder\n");
        goto done;
    }
    rspderlen = i2d_OCSP_RESPONSE(resp, &rspder);
    if (rspderlen <= 0)
        goto err;
    SSL_set_tlsext_status_ocsp_resp(s, rspder, rspderlen);
    if (srctx->verbose) {
        BIO_puts(bio_err, "cert_status: ocsp response sent:\n");
        OCSP_RESPONSE_print(bio_err, resp, 2);
    }
    ret = SSL_TLSEXT_ERR_OK;
 done:
    if (ret != SSL_TLSEXT_ERR_OK)
        ERR_print_errors(bio_err);
    if (aia) {
        OPENSSL_free(host);
        OPENSSL_free(path);
        OPENSSL_free(port);
        X509_email_free(aia);
    }
    OCSP_CERTID_free(id);
    OCSP_REQUEST_free(req);
    OCSP_RESPONSE_free(resp);
    return ret;
 err:
    ret = SSL_TLSEXT_ERR_ALERT_FATAL;
    goto done;
}
['static int cert_status_cb(SSL *s, void *arg)\n{\n    tlsextstatusctx *srctx = arg;\n    char *host = NULL, *port = NULL, *path = NULL;\n    int use_ssl;\n    unsigned char *rspder = NULL;\n    int rspderlen;\n    STACK_OF(OPENSSL_STRING) *aia = NULL;\n    X509 *x = NULL;\n    X509_STORE_CTX inctx;\n    X509_OBJECT obj;\n    OCSP_REQUEST *req = NULL;\n    OCSP_RESPONSE *resp = NULL;\n    OCSP_CERTID *id = NULL;\n    STACK_OF(X509_EXTENSION) *exts;\n    int ret = SSL_TLSEXT_ERR_NOACK;\n    int i;\n    if (srctx->verbose)\n        BIO_puts(bio_err, "cert_status: callback called\\n");\n    x = SSL_get_certificate(s);\n    aia = X509_get1_ocsp(x);\n    if (aia) {\n        if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),\n                            &host, &port, &path, &use_ssl)) {\n            BIO_puts(bio_err, "cert_status: can\'t parse AIA URL\\n");\n            goto err;\n        }\n        if (srctx->verbose)\n            BIO_printf(bio_err, "cert_status: AIA URL: %s\\n",\n                       sk_OPENSSL_STRING_value(aia, 0));\n    } else {\n        if (!srctx->host) {\n            BIO_puts(bio_err,\n                     "cert_status: no AIA and no default responder URL\\n");\n            goto done;\n        }\n        host = srctx->host;\n        path = srctx->path;\n        port = srctx->port;\n        use_ssl = srctx->use_ssl;\n    }\n    if (!X509_STORE_CTX_init(&inctx,\n                             SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),\n                             NULL, NULL))\n        goto err;\n    if (X509_STORE_get_by_subject(&inctx, X509_LU_X509,\n                                  X509_get_issuer_name(x), &obj) <= 0) {\n        BIO_puts(bio_err, "cert_status: Can\'t retrieve issuer certificate.\\n");\n        X509_STORE_CTX_cleanup(&inctx);\n        goto done;\n    }\n    req = OCSP_REQUEST_new();\n    if (req == NULL)\n        goto err;\n    id = OCSP_cert_to_id(NULL, x, obj.data.x509);\n    X509_free(obj.data.x509);\n    X509_STORE_CTX_cleanup(&inctx);\n    if (!id)\n        goto err;\n    if (!OCSP_request_add0_id(req, id))\n        goto err;\n    id = NULL;\n    SSL_get_tlsext_status_exts(s, &exts);\n    for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {\n        X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);\n        if (!OCSP_REQUEST_add_ext(req, ext, -1))\n            goto err;\n    }\n    resp = process_responder(req, host, path, port, use_ssl, NULL,\n                             srctx->timeout);\n    if (!resp) {\n        BIO_puts(bio_err, "cert_status: error querying responder\\n");\n        goto done;\n    }\n    rspderlen = i2d_OCSP_RESPONSE(resp, &rspder);\n    if (rspderlen <= 0)\n        goto err;\n    SSL_set_tlsext_status_ocsp_resp(s, rspder, rspderlen);\n    if (srctx->verbose) {\n        BIO_puts(bio_err, "cert_status: ocsp response sent:\\n");\n        OCSP_RESPONSE_print(bio_err, resp, 2);\n    }\n    ret = SSL_TLSEXT_ERR_OK;\n done:\n    if (ret != SSL_TLSEXT_ERR_OK)\n        ERR_print_errors(bio_err);\n    if (aia) {\n        OPENSSL_free(host);\n        OPENSSL_free(path);\n        OPENSSL_free(port);\n        X509_email_free(aia);\n    }\n    OCSP_CERTID_free(id);\n    OCSP_REQUEST_free(req);\n    OCSP_RESPONSE_free(resp);\n    return ret;\n err:\n    ret = SSL_TLSEXT_ERR_ALERT_FATAL;\n    goto done;\n}', 'int BIO_puts(BIO *b, const char *in)\n{\n    int i;\n    long (*cb) (BIO *, int, const char *, int, long, long);\n    if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {\n        BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);\n        return (-2);\n    }\n    cb = b->callback;\n    if ((cb != NULL) && ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0))\n        return (i);\n    if (!b->init) {\n        BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);\n        return (-2);\n    }\n    i = b->method->bputs(b, in);\n    if (i > 0)\n        b->num_write += (uint64_t)i;\n    if (cb != NULL)\n        i = (int)cb(b, BIO_CB_PUTS | BIO_CB_RETURN, in, 0, 0L, (long)i);\n    return (i);\n}', 'X509 *SSL_get_certificate(const SSL *s)\n{\n    if (s->cert != NULL)\n        return (s->cert->key->x509);\n    else\n        return (NULL);\n}', 'STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x)\n{\n    AUTHORITY_INFO_ACCESS *info;\n    STACK_OF(OPENSSL_STRING) *ret = NULL;\n    int i;\n    info = X509_get_ext_d2i(x, NID_info_access, NULL, NULL);\n    if (!info)\n        return NULL;\n    for (i = 0; i < sk_ACCESS_DESCRIPTION_num(info); i++) {\n        ACCESS_DESCRIPTION *ad = sk_ACCESS_DESCRIPTION_value(info, i);\n        if (OBJ_obj2nid(ad->method) == NID_ad_OCSP) {\n            if (ad->location->type == GEN_URI) {\n                if (!append_ia5\n                    (&ret, ad->location->d.uniformResourceIdentifier))\n                    break;\n            }\n        }\n    }\n    AUTHORITY_INFO_ACCESS_free(info);\n    return ret;\n}', 'void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)\n{\n    return X509V3_get_d2i(x->cert_info.extensions, nid, crit, idx);\n}']