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


apps/s_server.c:473:1: start of procedure cert_status_cb()
471.    */
472.   
473. > static int cert_status_cb(SSL *s, void *arg)
474.   {
475.       tlsextstatusctx *srctx = arg;

apps/s_server.c:475:5: 
473.   static int cert_status_cb(SSL *s, void *arg)
474.   {
475. >     tlsextstatusctx *srctx = arg;
476.       char *host = NULL, *port = NULL, *path = NULL;
477.       int use_ssl;

apps/s_server.c:476:5: 
474.   {
475.       tlsextstatusctx *srctx = arg;
476. >     char *host = NULL, *port = NULL, *path = NULL;
477.       int use_ssl;
478.       unsigned char *rspder = NULL;

apps/s_server.c:478:5: 
476.       char *host = NULL, *port = NULL, *path = NULL;
477.       int use_ssl;
478. >     unsigned char *rspder = NULL;
479.       int rspderlen;
480.       STACK_OF(OPENSSL_STRING) *aia = NULL;

apps/s_server.c:480:5: 
478.       unsigned char *rspder = NULL;
479.       int rspderlen;
480. >     STACK_OF(OPENSSL_STRING) *aia = NULL;
481.       X509 *x = NULL;
482.       X509_STORE_CTX *inctx = NULL;

apps/s_server.c:481:5: 
479.       int rspderlen;
480.       STACK_OF(OPENSSL_STRING) *aia = NULL;
481. >     X509 *x = NULL;
482.       X509_STORE_CTX *inctx = NULL;
483.       X509_OBJECT *obj;

apps/s_server.c:482:5: 
480.       STACK_OF(OPENSSL_STRING) *aia = NULL;
481.       X509 *x = NULL;
482. >     X509_STORE_CTX *inctx = NULL;
483.       X509_OBJECT *obj;
484.       OCSP_REQUEST *req = NULL;

apps/s_server.c:484:5: 
482.       X509_STORE_CTX *inctx = NULL;
483.       X509_OBJECT *obj;
484. >     OCSP_REQUEST *req = NULL;
485.       OCSP_RESPONSE *resp = NULL;
486.       OCSP_CERTID *id = NULL;

apps/s_server.c:485:5: 
483.       X509_OBJECT *obj;
484.       OCSP_REQUEST *req = NULL;
485. >     OCSP_RESPONSE *resp = NULL;
486.       OCSP_CERTID *id = NULL;
487.       STACK_OF(X509_EXTENSION) *exts;

apps/s_server.c:486:5: 
484.       OCSP_REQUEST *req = NULL;
485.       OCSP_RESPONSE *resp = NULL;
486. >     OCSP_CERTID *id = NULL;
487.       STACK_OF(X509_EXTENSION) *exts;
488.       int ret = SSL_TLSEXT_ERR_NOACK;

apps/s_server.c:488:5: 
486.       OCSP_CERTID *id = NULL;
487.       STACK_OF(X509_EXTENSION) *exts;
488. >     int ret = SSL_TLSEXT_ERR_NOACK;
489.       int i;
490.   

apps/s_server.c:491:9: Taking true branch
489.       int i;
490.   
491.       if (srctx->verbose)
               ^
492.           BIO_puts(bio_err, "cert_status: callback called\n");
493.       /* Build up OCSP query from server certificate */

apps/s_server.c:492:9: 
490.   
491.       if (srctx->verbose)
492. >         BIO_puts(bio_err, "cert_status: callback called\n");
493.       /* Build up OCSP query from server certificate */
494.       x = SSL_get_certificate(s);

crypto/bio/bio_lib.c:386:1: start of procedure BIO_puts()
  384.   }
  385.   
  386. > int BIO_puts(BIO *b, const char *buf)
  387.   {
  388.       int ret;

crypto/bio/bio_lib.c:389:5: 
  387.   {
  388.       int ret;
  389. >     size_t written = 0;
  390.   
  391.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {

crypto/bio/bio_lib.c:391:10: Taking false branch
  389.       size_t written = 0;
  390.   
  391.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
                  ^
  392.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
  393.           return -2;

crypto/bio/bio_lib.c:391:25: Taking false branch
  389.       size_t written = 0;
  390.   
  391.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
                                 ^
  392.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
  393.           return -2;

crypto/bio/bio_lib.c:391:48: Taking false branch
  389.       size_t written = 0;
  390.   
  391.       if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
                                                        ^
  392.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
  393.           return -2;

crypto/bio/bio_lib.c:396:9: Taking false branch
  394.       }
  395.   
  396.       if (b->callback != NULL || b->callback_ex != NULL) {
                 ^
  397.           ret = (int)bio_call_callback(b, BIO_CB_PUTS, buf, 0, 0, 0L, 1L, NULL);
  398.           if (ret <= 0)

crypto/bio/bio_lib.c:396:32: Taking false branch
  394.       }
  395.   
  396.       if (b->callback != NULL || b->callback_ex != NULL) {
                                        ^
  397.           ret = (int)bio_call_callback(b, BIO_CB_PUTS, buf, 0, 0, 0L, 1L, NULL);
  398.           if (ret <= 0)

crypto/bio/bio_lib.c:402:10: Taking true branch
  400.       }
  401.   
  402.       if (!b->init) {
                  ^
  403.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
  404.           return -2;

crypto/bio/bio_lib.c:403:9: Skipping ERR_put_error(): empty list of specs
  401.   
  402.       if (!b->init) {
  403.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
                 ^
  404.           return -2;
  405.       }

crypto/bio/bio_lib.c:404:9: 
  402.       if (!b->init) {
  403.           BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
  404. >         return -2;
  405.       }
  406.   

crypto/bio/bio_lib.c:429:1: return from a call to BIO_puts
  427.   
  428.       return ret;
  429. > }
  430.   
  431.   int BIO_gets(BIO *b, char *buf, int size)

apps/s_server.c:494:5: 
492.           BIO_puts(bio_err, "cert_status: callback called\n");
493.       /* Build up OCSP query from server certificate */
494. >     x = SSL_get_certificate(s);
495.       aia = X509_get1_ocsp(x);
496.       if (aia) {

ssl/ssl_lib.c:3255:1: start of procedure SSL_get_certificate()
  3253.   }
  3254.   
  3255. > X509 *SSL_get_certificate(const SSL *s)
  3256.   {
  3257.       if (s->cert != NULL)

ssl/ssl_lib.c:3257:9: Taking false branch
  3255.   X509 *SSL_get_certificate(const SSL *s)
  3256.   {
  3257.       if (s->cert != NULL)
                  ^
  3258.           return (s->cert->key->x509);
  3259.       else

ssl/ssl_lib.c:3260:9: 
  3258.           return (s->cert->key->x509);
  3259.       else
  3260. >         return (NULL);
  3261.   }
  3262.   

ssl/ssl_lib.c:3261:1: return from a call to SSL_get_certificate
  3259.       else
  3260.           return (NULL);
  3261. > }
  3262.   
  3263.   EVP_PKEY *SSL_get_privatekey(const SSL *s)

apps/s_server.c:495:5: 
493.       /* Build up OCSP query from server certificate */
494.       x = SSL_get_certificate(s);
495. >     aia = X509_get1_ocsp(x);
496.       if (aia) {
497.           if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),

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 = NULL;
    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;
    }
    inctx = X509_STORE_CTX_new();
    if (inctx == NULL)
        goto err;
    if (!X509_STORE_CTX_init(inctx,
                             SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),
                             NULL, NULL))
        goto err;
    obj = X509_STORE_CTX_get_obj_by_subject(inctx, X509_LU_X509,
                                            X509_get_issuer_name(x));
    if (obj == NULL) {
        BIO_puts(bio_err, "cert_status: Can't retrieve issuer certificate.\n");
        goto done;
    }
    id = OCSP_cert_to_id(NULL, x, X509_OBJECT_get0_X509(obj));
    X509_OBJECT_free(obj);
    if (!id)
        goto err;
    req = OCSP_REQUEST_new();
    if (req == NULL)
        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;
    goto done;
 err:
    ret = SSL_TLSEXT_ERR_ALERT_FATAL;
 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);
    X509_STORE_CTX_free(inctx);
    return ret;
}
['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 = NULL;\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    inctx = X509_STORE_CTX_new();\n    if (inctx == NULL)\n        goto err;\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    obj = X509_STORE_CTX_get_obj_by_subject(inctx, X509_LU_X509,\n                                            X509_get_issuer_name(x));\n    if (obj == NULL) {\n        BIO_puts(bio_err, "cert_status: Can\'t retrieve issuer certificate.\\n");\n        goto done;\n    }\n    id = OCSP_cert_to_id(NULL, x, X509_OBJECT_get0_X509(obj));\n    X509_OBJECT_free(obj);\n    if (!id)\n        goto err;\n    req = OCSP_REQUEST_new();\n    if (req == NULL)\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    goto done;\n err:\n    ret = SSL_TLSEXT_ERR_ALERT_FATAL;\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    X509_STORE_CTX_free(inctx);\n    return ret;\n}', 'int BIO_puts(BIO *b, const char *buf)\n{\n    int ret;\n    size_t written = 0;\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    if (b->callback != NULL || b->callback_ex != NULL) {\n        ret = (int)bio_call_callback(b, BIO_CB_PUTS, buf, 0, 0, 0L, 1L, NULL);\n        if (ret <= 0)\n            return ret;\n    }\n    if (!b->init) {\n        BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);\n        return -2;\n    }\n    ret = b->method->bputs(b, buf);\n    if (ret > 0) {\n        b->num_write += (uint64_t)ret;\n        written = ret;\n        ret = 1;\n    }\n    if (b->callback != NULL || b->callback_ex != NULL)\n        ret = (int)bio_call_callback(b, BIO_CB_PUTS | BIO_CB_RETURN, buf, 0, 0,\n                                     0L, ret, &written);\n    if (ret > 0) {\n        if (written > INT_MAX) {\n            BIOerr(BIO_F_BIO_PUTS, BIO_R_LENGTH_TOO_LONG);\n            ret = -1;\n        } else {\n            ret = (int)written;\n        }\n    }\n    return ret;\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}']