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;
}