Enforced secure socket rewrite on the same buffer address #4712
This commit is contained in:
parent
3e32d9fbee
commit
667b6f13c7
|
@ -469,33 +469,46 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needNewJob = false;
|
bool needNewJob = false;
|
||||||
static UInt32 s_retryOutputBufferSize = 0;
|
|
||||||
|
static bool s_retry = false;
|
||||||
|
static int s_retrySize = 0;
|
||||||
|
static void* s_staticBuffer = NULL;
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
try {
|
try {
|
||||||
// write data
|
// write data
|
||||||
int buffSize = m_outputBuffer.getSize();
|
int bufferSize = 0;
|
||||||
int bytesWrote = 0;
|
int bytesWrote = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
if (s_retryOutputBufferSize > 0) {
|
if (s_retry) {
|
||||||
buffSize = s_retryOutputBufferSize;
|
bufferSize = s_retrySize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bufferSize = m_outputBuffer.getSize();
|
||||||
|
s_staticBuffer = malloc(bufferSize);
|
||||||
|
memcpy(s_staticBuffer, m_outputBuffer.peek(bufferSize), bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* buffer = m_outputBuffer.peek(buffSize);
|
if (bufferSize == 0) {
|
||||||
|
return job;
|
||||||
|
}
|
||||||
|
|
||||||
if (isSecure()) {
|
if (isSecure()) {
|
||||||
if (isSecureReady()) {
|
if (isSecureReady()) {
|
||||||
status = secureWrite(buffer, buffSize, bytesWrote);
|
status = secureWrite(s_staticBuffer, bufferSize, bytesWrote);
|
||||||
if (status > 0) {
|
if (status > 0) {
|
||||||
s_retryOutputBufferSize = 0;
|
s_retry = false;
|
||||||
|
bufferSize = 0;
|
||||||
|
free(s_staticBuffer);
|
||||||
|
s_staticBuffer = NULL;
|
||||||
}
|
}
|
||||||
else if (status < 0) {
|
else if (status < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (status == 0) {
|
else if (status == 0) {
|
||||||
s_retryOutputBufferSize = buffSize;
|
s_retry = true;
|
||||||
|
s_retrySize = bufferSize;
|
||||||
return newJob();
|
return newJob();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,7 +517,10 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytesWrote = (UInt32)ARCH->writeSocket(m_socket, buffer, buffSize);
|
bytesWrote = (UInt32)ARCH->writeSocket(m_socket, s_staticBuffer, bufferSize);
|
||||||
|
bufferSize = 0;
|
||||||
|
free(s_staticBuffer);
|
||||||
|
s_staticBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// discard written data
|
// discard written data
|
||||||
|
|
Loading…
Reference in New Issue