sip: both framers read a Content-Length as a number
DatagramMessage read the first nine characters of a Content-Length, the zeros before its number among them: a length written 0000000005 came out as 0, and the body after it was cut off as bytes past the message. FrameBuffer read the value into a long, and one too long for that counted as no Content-Length: the body was framed as the start of the next message. RFC 3261 25.1 writes the value as 1*DIGIT. LengthOf reads it for both: the number its leading digits spell, zeros before it aside; of a number of more than nine digits the first nine, more than a datagram holds and enough that a stream waits. A value that begins with no digit is no length, as before. Tested by tests/Sip through both framers: a length of one digit written with ten zeros before it frames that many bytes; a twenty-digit length that wraps to zero in 64 bits is a datagram cut short and a stream's body waited for; a value without a leading digit leaves a datagram's body the rest of it and a stream's empty.
This commit is contained in:
parent
78c702546a
commit
c81dd3d267
3 changed files with 40 additions and 10 deletions
|
|
@ -5,11 +5,12 @@
|
|||
// the colon among it), status-line parsing, granted-expires extraction,
|
||||
// caller-identity extraction, the port a Via names for the response
|
||||
// (ViaResponsePort), the two framers — the TCP frame buffer (split delivery,
|
||||
// keepalive pongs, pipelined messages) and a datagram's (DatagramMessage) —,
|
||||
// a refused final's Retry-After and summary (RetryAfter, RefusalSummary),
|
||||
// transaction matching (ResponseOf), our binding in a reg-event document
|
||||
// (RegInfoContactState), and HeaderUri and Body. These pin the module's
|
||||
// edge-case behavior; see the module header before "fixing" one.
|
||||
// keepalive pongs, pipelined messages) and a datagram's (DatagramMessage),
|
||||
// with the Content-Length they read —, a refused final's Retry-After and
|
||||
// summary (RetryAfter, RefusalSummary), transaction matching (ResponseOf),
|
||||
// our binding in a reg-event document (RegInfoContactState), and HeaderUri
|
||||
// and Body. These pin the module's edge-case behavior; see the module header
|
||||
// before "fixing" one.
|
||||
import std;
|
||||
import Imsd;
|
||||
|
||||
|
|
@ -181,6 +182,16 @@ int main() {
|
|||
Check(fb.TryExtract() == msg, "no Content-Length -> body length 0");
|
||||
Check(fb.Size() == 8, "trailing bytes stay buffered");
|
||||
}
|
||||
{
|
||||
// the Content-Length is read as a number: zeros before it do not count, and one too long to be a length is no zero
|
||||
const std::string head = "SIP/2.0 200 OK\r\nCall-ID: x\r\n";
|
||||
FrameBuffer fb;
|
||||
fb.Append(head + "Content-Length: 00000000005\r\n\r\nhello" + head + "Content-Length: 000\r\n\r\n" + head + "Content-Length: x\r\n\r\n");
|
||||
Check(fb.TryExtract() == head + "Content-Length: 00000000005\r\n\r\nhello", "a Content-Length of 5 written with ten zeros before it frames a body of five bytes");
|
||||
Check(fb.TryExtract() == head + "Content-Length: 000\r\n\r\n" && fb.TryExtract() == head + "Content-Length: x\r\n\r\n" && fb.Size() == 0, "zero in three digits is zero, and a value without a digit counts as none");
|
||||
fb.Append(head + "Content-Length: 18446744073709551616\r\n\r\nhello");
|
||||
Check(!fb.TryExtract().has_value() && fb.Size() > 0, "a Content-Length past any number that fits is not read as zero: the body is waited for");
|
||||
}
|
||||
{
|
||||
// the body's length under the compact name (RFC 3261 7.3.3), and with a space before the colon (7.3.1)
|
||||
const std::string compact = "MESSAGE sip:a@b SIP/2.0\r\ni: c1@h\r\nl: 5\r\n\r\nhello";
|
||||
|
|
@ -305,6 +316,10 @@ int main() {
|
|||
Check(m3 && *m3 == hdr + "X-Note: Content-Length: 99\r\n\r\nv=0\n", "a header name inside a value does not match");
|
||||
auto m4 = DatagramMessage(hdr + "Content-Length: 99999999999999999999\r\n\r\nv=0\n", &why);
|
||||
Check(!m4.has_value(), "absurd Content-Length: discarded, no overflow");
|
||||
why.clear();
|
||||
Check(!DatagramMessage(hdr + "Content-Length: 18446744073709551616\r\n\r\nv=0\n", &why).has_value() && why.contains("truncated"), "nor is one that would wrap to zero: discarded as truncated");
|
||||
Check(DatagramMessage(hdr + "Content-Length: 00000000004\r\n\r\nv=0\nJUNK") == hdr + "Content-Length: 00000000004\r\n\r\nv=0\n", "a Content-Length of 4 written with ten zeros before it cuts the body at four bytes");
|
||||
Check(DatagramMessage(hdr + "Content-Length: x4\r\n\r\nv=0\nJUNK") == hdr + "Content-Length: x4\r\n\r\nv=0\nJUNK", "a Content-Length that begins with no digit: the body is the rest of the datagram");
|
||||
auto m5 = DatagramMessage(hdr + "l: 4\r\n\r\nv=0\nJUNK");
|
||||
Check(m5 && *m5 == hdr + "l: 4\r\n\r\nv=0\n", "`l:` that fits truncates the body like Content-Length");
|
||||
why.clear();
|
||||
|
|
|
|||
Loading…
Reference in a new issue