summaryrefslogtreecommitdiffstats
path: root/lib/libtdekrb/src/tdekrbclientsocket.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-26 18:31:55 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-26 18:31:55 -0500
commitb2f2dba837c0d28bf73ec36933af901f484633f5 (patch)
tree94384fc6fb158c0da05383617b6c2c49a094b059 /lib/libtdekrb/src/tdekrbclientsocket.cpp
parentdb2e4f26fec407b7044d3b680c0745500af6290f (diff)
downloadulab-b2f2dba837c0d28bf73ec36933af901f484633f5.tar.gz
ulab-b2f2dba837c0d28bf73ec36933af901f484633f5.zip
Remove limitation on written data length and fix crash
Diffstat (limited to 'lib/libtdekrb/src/tdekrbclientsocket.cpp')
-rw-r--r--lib/libtdekrb/src/tdekrbclientsocket.cpp60
1 files changed, 42 insertions, 18 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;
}