Changeset b674e95 in mod_gnutls for src/gnutls_io.c


Ignore:
Timestamp:
May 29, 2016, 3:38:07 PM (3 years ago)
Author:
Thomas Klute <thomas2.klute@…>
Branches:
debian/master, debian/stretch-backports, master, upstream
Children:
94cb972
Parents:
efe884e (diff), 086cea9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Thomas Klute <thomas2.klute@…> (05/29/16 15:28:14)
git-committer:
Thomas Klute <thomas2.klute@…> (05/29/16 15:38:07)
Message:

Merge version 0.7.5 into ocsp branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_io.c

    refe884e rb674e95  
    765765/**
    766766 * Pull function for GnuTLS
     767 *
     768 * Generic errnos used for gnutls_transport_set_errno:
     769 * EIO: Unknown I/O error
     770 * ECONNABORTED: Input BB does not exist (NULL)
     771 *
     772 * The reason we are not using APR_TO_OS_ERROR to map apr_status_t to
     773 * errnos is this warning in the APR documentation: "If the statcode
     774 * was not created by apr_get_os_error or APR_FROM_OS_ERROR, the
     775 * results are undefined." We cannot know if this applies to any error
     776 * we might encounter.
    767777 */
    768778ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
     
    777787
    778788    /* If Len = 0, we don't do anything. */
    779     if (!len || buffer == NULL) {
     789    if (!len || buffer == NULL)
     790    {
    780791        return 0;
    781792    }
    782     if (!ctxt->input_bb) {
     793    /* Input bucket brigade is missing, EOF */
     794    if (!ctxt->input_bb)
     795    {
    783796        ctxt->input_rc = APR_EOF;
     797        gnutls_transport_set_errno(ctxt->session, ECONNABORTED);
    784798        return -1;
    785799    }
    786800
    787     if (APR_BRIGADE_EMPTY(ctxt->input_bb)) {
    788 
     801    if (APR_BRIGADE_EMPTY(ctxt->input_bb))
     802    {
    789803        rc = ap_get_brigade(ctxt->input_filter->next,
    790                 ctxt->input_bb, AP_MODE_READBYTES,
    791                 ctxt->input_block, in);
     804                            ctxt->input_bb, AP_MODE_READBYTES,
     805                            ctxt->input_block, in);
    792806
    793807        /* Not a problem, there was simply no data ready yet.
     
    803817            else
    804818            {
    805                 if (ctxt->session)
    806                     gnutls_transport_set_errno(ctxt->session,
    807                                                EAI_APR_TO_RAW(ctxt->input_rc));
     819                gnutls_transport_set_errno(ctxt->session,
     820                                           EAI_APR_TO_RAW(ctxt->input_rc));
    808821                return -1;
    809822            }
    810823        }
    811824
    812         if (rc != APR_SUCCESS) {
     825        if (rc != APR_SUCCESS)
     826        {
    813827            /* Unexpected errors discard the brigade */
    814828            apr_brigade_cleanup(ctxt->input_bb);
    815829            ctxt->input_bb = NULL;
     830            gnutls_transport_set_errno(ctxt->session, EIO);
    816831            return -1;
    817832        }
    818833    }
    819834
    820     ctxt->input_rc =
    821             brigade_consume(ctxt->input_bb, block, buffer, &len);
    822 
    823     if (ctxt->input_rc == APR_SUCCESS) {
     835    ctxt->input_rc = brigade_consume(ctxt->input_bb, block, buffer, &len);
     836
     837    if (ctxt->input_rc == APR_SUCCESS)
     838    {
    824839        return (ssize_t) len;
    825840    }
     
    830845        if (len == 0)
    831846        {
    832             if (ctxt->session)
    833                 gnutls_transport_set_errno(ctxt->session,
    834                                            EAI_APR_TO_RAW(ctxt->input_rc));
     847            gnutls_transport_set_errno(ctxt->session,
     848                                       EAI_APR_TO_RAW(ctxt->input_rc));
    835849            return -1;
    836850        }
     
    840854
    841855    /* Unexpected errors and APR_EOF clean out the brigade.
    842      * Subsequent calls will return APR_EOF.
    843      */
     856     * Subsequent calls will return APR_EOF. */
    844857    apr_brigade_cleanup(ctxt->input_bb);
    845858    ctxt->input_bb = NULL;
    846859
    847     if (APR_STATUS_IS_EOF(ctxt->input_rc) && len) {
    848         /* Provide the results of this read pass,
    849          * without resetting the BIO retry_read flag
    850          */
     860    if (APR_STATUS_IS_EOF(ctxt->input_rc) && len)
     861    {
     862        /* Some data has been received before EOF, return it. */
    851863        return (ssize_t) len;
    852864    }
    853865
     866    gnutls_transport_set_errno(ctxt->session, EIO);
    854867    return -1;
    855868}
    856869
     870/**
     871 * Push function for GnuTLS
     872 *
     873 * In case of unexpected errors gnutls_transport_set_errno is called
     874 * with EIO.  The reason we are not using APR_TO_OS_ERROR to map
     875 * apr_status_t to errnos is this warning in the APR documentation:
     876 * "If the statcode was not created by apr_get_os_error or
     877 * APR_FROM_OS_ERROR, the results are undefined." We cannot know if
     878 * this applies to any error we might encounter.
     879 */
    857880ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
    858         const void *buffer, size_t len) {
     881                            const void *buffer, size_t len)
     882{
    859883    mgs_handle_t *ctxt = ptr;
    860884
     
    869893    APR_BRIGADE_INSERT_TAIL(ctxt->output_bb, bucket);
    870894
    871     if (write_flush(ctxt) < 0) {
     895    if (write_flush(ctxt) < 0)
     896    {
     897        /* We encountered an error. APR_EINTR or APR_EAGAIN can be
     898         * handled, treat everything else as a generic I/O error. */
     899        int err = EIO;
     900        if (APR_STATUS_IS_EAGAIN(ctxt->output_rc)
     901            || APR_STATUS_IS_EINTR(ctxt->output_rc))
     902            err = EAI_APR_TO_RAW(ctxt->output_rc);
     903
     904        gnutls_transport_set_errno(ctxt->session, err);
    872905        return -1;
    873906    }
Note: See TracChangeset for help on using the changeset viewer.