< Previous by Date | Date Index | Next by Date > |
< Previous in Thread | Thread Index | Next in Thread > |
inline
Ah! We had a terminology problem. I was interpreting "header" to mean the set of all header fields in the SIP message. Your problem now makes much more sense to me now.
Ok, now I see what you're talking about. Yes, this is a problem.
Ok, on closer inspection, I see the code that will limit the size of individual read calls. So, as the code sits right now, it _looks_ like the only thing that causes the chunk size to get unreasonably large is the case you describe. I think we would be better off instead limiting the size of numUnprocessedChars when the MsgHeaderScanner returns scrNextChunk; this more directly addresses the problem I think. A patch might look like this: Index: resip/stack/ConnectionBase.cxx =================================================================== --- resip/stack/ConnectionBase.cxx (revision 8120) +++ resip/stack/ConnectionBase.cxx (working copy) @@ -176,16 +176,26 @@ else { // ...but some of the chunk must be shifted into the next one. - size_t size = numUnprocessedChars*3/2; - if (size < ConnectionBase::ChunkSize) + if (numUnprocessedChars >= ConnectionBase::ChunkSize) { - size = ConnectionBase::ChunkSize; + // .bwc. We have lots of unprocessed chars here; this can be + // caused if we get a really, really large header field value. + // We can safely reject this, I think. + delete [] mBuffer; + mBuffer = 0; + delete mMessage; + mMessage = 0; + //.jacob. Shouldn't the state also be set here? + delete this; + return; } - char* newBuffer = MsgHeaderScanner::allocateBuffer(size); + + // ?bwc? Maybe do a slightly larger buffer here? + char* newBuffer = MsgHeaderScanner::allocateBuffer(ConnectionBase::ChunkSize); memcpy(newBuffer, unprocessedCharPtr, numUnprocessedChars); mBuffer = newBuffer; mBufferPos = numUnprocessedChars; - mBufferSize = size; + mBufferSize = ConnectionBase::ChunkSize; } mConnState = ReadingHeaders; } What do people think? Additionally, as long as we're rooting around in this code, we should take the time to re-examine how we allocate buffers for the contents of a SIP message; we're allocating a buffer based on the assurances of the Content-Length field, but I don't think we should be doing this. I think we should _record_ what the Content-Length claims, but only allocate space as stuff comes in. (It would be easy to open up bunches of connections with SIP messages claiming to have really large (10M) payloads, but never send the bits, causing massive memory waste). Best regards, Byron Campen |
Attachment:
smime.p7s
Description: S/MIME cryptographic signature