Skip to content
Snippets Groups Projects
Commit 8ca874d7 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

tls_session: fix extra packet send by gnutls

Sometimes the gnutls function gnutls_record_send() reports
to have sent more bytes than given.
This is happen if we don't flush the internal state of gnutls records
or if we don't try to loop with same arguments until we get a positive
value or not GNUTLS_E_INTERRUPTED neither GNUTLS_E_AGAIN.
When not done correctly the receiption see 2 packets: one of the
correct size and another with extra bytes, filled with zero's.

This patch fixes this situation by loop on the gnutls send function
until we get a return value different of ones given upper.
We ensure also to return -1 in case of error in low-level send functions.

Change-Id: I209ceba2e25fc7b299c38348cf36801a722af2d7
Tuleap: #798
parent 46285595
Branches
Tags
No related merge requests found
......@@ -422,7 +422,11 @@ TlsSession::send_(const uint8_t* tx_data, std::size_t tx_size)
size_t total_written = 0;
while (total_written < tx_size) {
auto chunck_sz = std::min(max_tx_sz, tx_size - total_written);
auto nwritten = gnutls_record_send(session_, tx_data + total_written, chunck_sz);
ssize_t nwritten;
auto data_seq = tx_data + total_written;
do {
nwritten = gnutls_record_send(session_, data_seq, chunck_sz);
} while (nwritten == GNUTLS_E_INTERRUPTED or nwritten == GNUTLS_E_AGAIN);
if (nwritten <= 0) {
/* Normally we would have to retry record_send but our internal
* state has not changed, so we have to ask for more data first.
......@@ -448,8 +452,9 @@ TlsSession::sendRaw(const void* buf, size_t size)
// log only on success
++stTxRawPacketCnt_;
stTxRawBytesCnt_ += size;
return ret;
}
return ret;
return -1;
}
// Called by GNUTLS to send encrypted packet to low-level transport.
......@@ -462,7 +467,7 @@ TlsSession::sendRawVec(const giovec_t* iov, int iovcnt)
const giovec_t& dat = iov[i];
ssize_t ret = sendRaw(dat.iov_base, dat.iov_len);
if (ret < 0)
return ret;
return -1;
sent += ret;
}
return sent;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment