diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-26 18:31:55 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-26 18:31:55 -0500 |
commit | b2f2dba837c0d28bf73ec36933af901f484633f5 (patch) | |
tree | 94384fc6fb158c0da05383617b6c2c49a094b059 | |
parent | db2e4f26fec407b7044d3b680c0745500af6290f (diff) | |
download | ulab-b2f2dba837c0d28bf73ec36933af901f484633f5.tar.gz ulab-b2f2dba837c0d28bf73ec36933af901f484633f5.zip |
Remove limitation on written data length and fix crash
-rw-r--r-- | lib/libtdekrb/src/tdekrbclientsocket.cpp | 60 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbserversocket.cpp | 60 |
2 files changed, 84 insertions, 36 deletions
diff --git a/lib/libtdekrb/src/tdekrbclientsocket.cpp b/lib/libtdekrb/src/tdekrbclientsocket.cpp index 546c7f2..647da73 100644 --- a/lib/libtdekrb/src/tdekrbclientsocket.cpp +++ b/lib/libtdekrb/src/tdekrbclientsocket.cpp @@ -221,10 +221,12 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) { int wrlen; char* buf = (char*)malloc(m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } free(buf); @@ -273,10 +275,12 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) { int wrlen; char* buf = (char*)malloc(m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } free(buf); @@ -313,10 +317,12 @@ TQString TDEKerberosClientSocket::readLine() { int readlen; char* buf = (char*)malloc(m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } free(buf); @@ -447,13 +453,31 @@ int TDEKerberosClientSocket::transmitEncryptedData(int fd, const char* readbuf, int result = 0; unsigned int len; const char *data; - - result=sasl_encode(saslData->m_krbConnection, readbuf, cc, &data, &len); - if (result != SASL_OK) { - printf("[ERROR] Encrypting data returned %s (%d)\n\r", safe_sasl_errdetail(saslData->m_krbConnection), result); - return -1; + long data_remaining; + long remnant_position; + + data_remaining = cc; + remnant_position = 0; + while (data_remaining > 0) { + int data_to_write_len; + if (data_remaining > (m_negotiatedMaxBufferSize/2)) { + data_to_write_len = m_negotiatedMaxBufferSize/2; + } + else { + data_to_write_len = data_remaining; + } + result=sasl_encode(saslData->m_krbConnection, readbuf+remnant_position, data_to_write_len, &data, &len); + if (result != SASL_OK) { + printf("[ERROR] Encrypting data returned %s (%d)\n\r", safe_sasl_errdetail(saslData->m_krbConnection), result); + return -1; + } + sendSASLDataToNetwork(data, len, fd); + data_remaining = data_remaining - data_to_write_len; + remnant_position = remnant_position + data_to_write_len; + if (data_remaining > 0) { + tqApp->processEvents(); + } } - sendSASLDataToNetwork(data, len, fd); return 0; } diff --git a/lib/libtdekrb/src/tdekrbserversocket.cpp b/lib/libtdekrb/src/tdekrbserversocket.cpp index b415b2e..2b4d7d2 100644 --- a/lib/libtdekrb/src/tdekrbserversocket.cpp +++ b/lib/libtdekrb/src/tdekrbserversocket.cpp @@ -221,10 +221,12 @@ TQ_LONG TDEKerberosServerSocket::readBlock(char *data, TQ_ULONG maxlen) { int wrlen; char* buf = (char*)malloc(m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } free(buf); @@ -273,10 +275,12 @@ TQ_LONG TDEKerberosServerSocket::readLine(char *data, TQ_ULONG maxlen) { int wrlen; char* buf = (char*)malloc(m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } free(buf); @@ -313,10 +317,12 @@ TQString TDEKerberosServerSocket::readLine() { int readlen; char* buf = (char*)malloc(m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } free(buf); @@ -447,13 +453,31 @@ int TDEKerberosServerSocket::transmitEncryptedData(int fd, const char* readbuf, int result = 0; unsigned int len; const char *data; - - result=sasl_encode(saslData->m_krbConnection, readbuf, cc, &data, &len); - if (result != SASL_OK) { - printf("[ERROR] Encrypting data returned %s (%d)\n\r", safe_sasl_errdetail(saslData->m_krbConnection), result); - return -1; + long data_remaining; + long remnant_position; + + data_remaining = cc; + remnant_position = 0; + while (data_remaining > 0) { + int data_to_write_len; + if (data_remaining > (m_negotiatedMaxBufferSize/2)) { + data_to_write_len = m_negotiatedMaxBufferSize/2; + } + else { + data_to_write_len = data_remaining; + } + result=sasl_encode(saslData->m_krbConnection, readbuf+remnant_position, data_to_write_len, &data, &len); + if (result != SASL_OK) { + printf("[ERROR] Encrypting data returned %s (%d)\n\r", safe_sasl_errdetail(saslData->m_krbConnection), result); + return -1; + } + sendSASLDataToNetwork(data, len, fd); + data_remaining = data_remaining - data_to_write_len; + remnant_position = remnant_position + data_to_write_len; + if (data_remaining > 0) { + tqApp->processEvents(); + } } - sendSASLDataToNetwork(data, len, fd); return 0; } |