diff --git a/ChangeLog b/ChangeLog index b58b78fb..aa7d53eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-01-19 Gonzalo Paniagua Javier + + * server/XSPWorkerRequest.cs: when Content-Length is set only allow + sending that amount of bytes in the body. Fixes bug #71092. + 2005-01-13 Raja R Harinath * server/MonoWorkerRequest.cs: Update to compile with the stricter diff --git a/server/XSPWorkerRequest.cs b/server/XSPWorkerRequest.cs index eb18bb97..e3e793e3 100644 --- a/server/XSPWorkerRequest.cs +++ b/server/XSPWorkerRequest.cs @@ -68,6 +68,8 @@ public class XSPWorkerRequest : MonoWorkerRequest XSPRequestBroker requestBroker; bool keepAlive; bool haveContentLength; + long contentSent; + long contentLength; bool isclosed; static string serverHeader; @@ -297,6 +299,18 @@ void AddConnectionHeader () responseHeaders.Append ("Connection: Keep-Alive\r\n"); } + int UpdateBodyLength (int currentBlockLength) + { + if (!haveContentLength || contentSent < contentLength - currentBlockLength) { + contentSent += currentBlockLength; + return currentBlockLength; + } + + int result = (int) (contentLength - contentSent); + contentSent = contentLength; + return result; + } + public override void FlushResponse (bool finalFlush) { if (requestBroker == null) @@ -318,6 +332,7 @@ public override void FlushResponse (bool finalFlush) if (oldLength == 0 || oldLength >= 32768) { requestBroker.Write (requestId, headerBytes, 0, headerBytes.Length); } else { + oldLength = UpdateBodyLength (oldLength); // Attempt not to send a minimum of 2 packets int newLength = oldLength + headerBytes.Length; response.SetLength (newLength); @@ -333,7 +348,8 @@ public override void FlushResponse (bool finalFlush) if (response.Length != 0) { byte [] bytes = response.GetBuffer (); - requestBroker.Write (requestId, bytes, 0, (int) response.Length); + int len = UpdateBodyLength ((int) response.Length); + requestBroker.Write (requestId, bytes, 0, len); } if (finalFlush) @@ -625,8 +641,10 @@ public override void SendUnknownResponseHeader (string name, string value) } if (!sentConnection && !haveContentLength && - String.Compare (name, "Content-Length", true, CultureInfo.InvariantCulture) == 0) + String.Compare (name, "Content-Length", true, CultureInfo.InvariantCulture) == 0) { haveContentLength = true; + contentLength = Int64.Parse (value); // This should work, otherwise HttpResponse throws. + } if (!headersSent) { responseHeaders.Append (name);