From b07bbb4f73c9d2abbdab5db0b064379981db11bc Mon Sep 17 00:00:00 2001 From: Fu Siyuan Date: Wed, 20 Sep 2017 11:21:56 +0800 Subject: [PATCH] MdeModulePkg/DxeNetLib: Check the actual packet size before trim data from Nbuf. In NetbufTrim() function, the NetBuf TotalSize should be checked with 0 before making the trim operation, otherwise the function will fall into infinite loop. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan Reviewed-by: Wu Jiaxin --- MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c index 95cb71714b..d0e2b9f2a8 100644 --- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c +++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c @@ -1,7 +1,7 @@ /** @file Network library functions providing net buffer operation support. -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1175,6 +1175,10 @@ NetbufTrim ( NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE); + if (Len == 0 || Nbuf->TotalSize == 0) { + return 0; + } + if (Len > Nbuf->TotalSize) { Len = Nbuf->TotalSize; }