summaryrefslogtreecommitdiffstats
path: root/NetworkPkg
diff options
context:
space:
mode:
authorVladimir Olovyannikov via groups.io <vladimir.olovyannikov=broadcom.com@groups.io>2020-08-28 11:17:06 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-10-09 10:40:33 +0000
commit70c2f10fde5b67b0d7d62ba7ea3271fc514ebcc4 (patch)
tree0f60ad37c10a84616e57d183d4762810a5db3413 /NetworkPkg
parent5df413119ec80cb462bf9c888ef5574f8ce8ae2e (diff)
downloadedk2-70c2f10fde5b67b0d7d62ba7ea3271fc514ebcc4.tar.gz
edk2-70c2f10fde5b67b0d7d62ba7ea3271fc514ebcc4.tar.bz2
edk2-70c2f10fde5b67b0d7d62ba7ea3271fc514ebcc4.zip
NetworkPkg: Fix possible infinite loop in HTTP msg body parser
When an HTTP server sends a non-chunked body data with no Content-Length header, the HttpParserMessageBody in DxeHttpLib gets confused and never sets the Char pointer beyond the body start. This causes "for" loop to never break because the condition of "Char >= Body + BodyLength" is never satisfied. Use BodyLength as the ContentLength for the parser when ContentLength is absent in HTTP response headers. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2941 Signed-off-by: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com> Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com> Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Diffstat (limited to 'NetworkPkg')
-rw-r--r--NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c b/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c
index 180d932102..daec1e0226 100644
--- a/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -1122,6 +1122,7 @@ HttpParseMessageBody (
CHAR8 *Char;
UINTN RemainderLengthInThis;
UINTN LengthForCallback;
+ UINTN PortionLength;
EFI_STATUS Status;
HTTP_BODY_PARSER *Parser;
@@ -1173,19 +1174,31 @@ HttpParseMessageBody (
//
// Identity transfer-coding, just notify user to save the body data.
//
+ PortionLength = MIN (
+ BodyLength,
+ Parser->ContentLength - Parser->ParsedBodyLength
+ );
+ if (PortionLength == 0) {
+ //
+ // Got BodyLength, but no ContentLength. Use BodyLength.
+ //
+ PortionLength = BodyLength;
+ Parser->ContentLength = PortionLength;
+ }
+
if (Parser->Callback != NULL) {
Status = Parser->Callback (
BodyParseEventOnData,
Char,
- MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength),
+ PortionLength,
Parser->Context
);
if (EFI_ERROR (Status)) {
return Status;
}
}
- Char += MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength);
- Parser->ParsedBodyLength += MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength);
+ Char += PortionLength;
+ Parser->ParsedBodyLength += PortionLength;
if (Parser->ParsedBodyLength == Parser->ContentLength) {
Parser->State = BodyParserComplete;
if (Parser->Callback != NULL) {