From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 86B4F21E3EA67 for ; Tue, 19 Sep 2017 20:21:05 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Sep 2017 20:24:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,420,1500966000"; d="scan'208";a="130527670" Received: from sfu5-mobl.ccr.corp.intel.com ([10.239.193.42]) by orsmga004.jf.intel.com with ESMTP; 19 Sep 2017 20:24:00 -0700 From: Fu Siyuan To: edk2-devel@lists.01.org Cc: Wu Jiaxin , Ye Ting , Michael Turner Date: Wed, 20 Sep 2017 11:23:57 +0800 Message-Id: <20170920032357.5864-1-siyuan.fu@intel.com> X-Mailer: git-send-email 2.13.0.windows.1 Subject: [Patch] MdeModulePkg/DxeNetLib: Check the actual packet size before trim data from Nbuf. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Sep 2017 03:21:05 -0000 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 Cc: Wu Jiaxin Cc: Ye Ting Cc: Michael Turner --- MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c index 95cb71714b..25fc78e49e 100644 --- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c +++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c @@ -1175,6 +1175,10 @@ NetbufTrim ( NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE); + if (Nbuf->TotalSize == 0) { + return 0; + } + if (Len > Nbuf->TotalSize) { Len = Nbuf->TotalSize; } -- 2.13.0.windows.1