Remove limitation on written data length and fix crash

master
Timothy Pearson 13 years ago
parent db2e4f26fe
commit b2f2dba837

@ -221,11 +221,13 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) {
int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen > 0) {
m_buffer->at(m_bufferLength);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
}
}
free(buf);
m_buffer->at(0);
@ -273,11 +275,13 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) {
int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen > 0) {
m_buffer->at(m_bufferLength);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
}
}
free(buf);
m_buffer->at(0);
@ -313,11 +317,13 @@ TQString TDEKerberosClientSocket::readLine() {
int readlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen > 0) {
m_buffer->at(m_bufferLength);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
}
}
free(buf);
m_buffer->at(0);
@ -447,13 +453,31 @@ int TDEKerberosClientSocket::transmitEncryptedData(int fd, const char* readbuf,
int result = 0;
unsigned int len;
const char *data;
long data_remaining;
long remnant_position;
result=sasl_encode(saslData->m_krbConnection, readbuf, cc, &data, &len);
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();
}
}
return 0;
}

@ -221,11 +221,13 @@ TQ_LONG TDEKerberosServerSocket::readBlock(char *data, TQ_ULONG maxlen) {
int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen > 0) {
m_buffer->at(m_bufferLength);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
}
}
free(buf);
m_buffer->at(0);
@ -273,11 +275,13 @@ TQ_LONG TDEKerberosServerSocket::readLine(char *data, TQ_ULONG maxlen) {
int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen > 0) {
m_buffer->at(m_bufferLength);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
}
}
free(buf);
m_buffer->at(0);
@ -313,11 +317,13 @@ TQString TDEKerberosServerSocket::readLine() {
int readlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen > 0) {
m_buffer->at(m_bufferLength);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
}
}
free(buf);
m_buffer->at(0);
@ -447,13 +453,31 @@ int TDEKerberosServerSocket::transmitEncryptedData(int fd, const char* readbuf,
int result = 0;
unsigned int len;
const char *data;
long data_remaining;
long remnant_position;
result=sasl_encode(saslData->m_krbConnection, readbuf, cc, &data, &len);
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();
}
}
return 0;
}

Loading…
Cancel
Save