Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions dcmpstat/libsrc/dvpsmsg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#define PAYLOAD_ALLOCATION_UNIT 1024
#define PAYLOAD_OFFSET 8
#define PAYLOAD_MAX_SIZE (64 * 1024)

// constants for message type
const Uint32 DVPSIPCMessage::OK = 0;
Expand Down Expand Up @@ -162,7 +163,11 @@ OFBool DVPSIPCMessage::extractStringFromPayload(OFString& str)
// check if we have sufficient data available
if (payloadReadOffset + length > payloadUsed) return OFFalse;

str = (const char *)(payload+payloadReadOffset); // guaranteed to be zero terminated string
// do not assume the payload is zero terminated: scan at most 'length' bytes
const char *strStart = (const char *)(payload+payloadReadOffset);
Uint32 strLen = 0;
while (strLen < length && strStart[strLen] != '\0') ++strLen;
str.assign(strStart, strLen);
payloadReadOffset += length;
return OFTrue;
}
Expand Down Expand Up @@ -215,12 +220,19 @@ OFBool DVPSIPCMessage::receive(DcmTransportConnection &connection)
messageType = *(Uint32 *)payload;
payloadUsed = *(Uint32 *)(payload+sizeof(Uint32));

// reject implausibly large payloads read from the network
if (payloadUsed > PAYLOAD_MAX_SIZE)
{
payloadUsed = PAYLOAD_OFFSET;
return OFFalse;
}

// check if we need to allocate more memory
Uint32 requiredSize = payloadUsed + PAYLOAD_OFFSET;
if (requiredSize > payloadAllocated)
{
delete[] payload;
while (payloadAllocated < requiredSize) payloadAllocated += PAYLOAD_ALLOCATION_UNIT;
delete[] payload;
payload = new unsigned char[payloadAllocated];
}

Expand Down
Loading