summaryrefslogtreecommitdiffstats
path: root/MdePkg
diff options
context:
space:
mode:
authorEric Dong <eric.dong@intel.com>2016-10-27 11:08:37 +0800
committerStar Zeng <star.zeng@intel.com>2016-11-09 17:49:15 +0800
commitc0cba3d5ddec83e2bf09deb01a25140a71f8b7e6 (patch)
tree0b3f5535b200b046583ae97bade051d6d75f6a89 /MdePkg
parent1420143f014a4c14bd7cb430aaacd6b2c4bc8043 (diff)
downloadedk2-c0cba3d5ddec83e2bf09deb01a25140a71f8b7e6.tar.gz
edk2-c0cba3d5ddec83e2bf09deb01a25140a71f8b7e6.tar.bz2
edk2-c0cba3d5ddec83e2bf09deb01a25140a71f8b7e6.zip
MdePkg DevicePathLib: Validate before touch input buffer.
Current code not validate the input buffer before touch. it may touch the buffer outside the validate scope. This patch validate the input size big enough to touch the first node. Cc: Ruiyu NI <ruiyu.ni@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong <eric.dong@intel.com>
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
index a514f1b6f9..2252d186cb 100644
--- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
+++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
@@ -103,17 +103,33 @@ IsDevicePathValid (
ASSERT (DevicePath != NULL);
+ if (MaxSize == 0) {
+ MaxSize = MAX_UINTN;
+ }
+
+ //
+ // Validate the input size big enough to touch the first node.
+ //
+ if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
+ return FALSE;
+ }
+
for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
NodeLength = DevicePathNodeLength (DevicePath);
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
return FALSE;
}
- if (MaxSize > 0) {
- Size += NodeLength;
- if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {
- return FALSE;
- }
+ if (NodeLength > MAX_UINTN - Size) {
+ return FALSE;
+ }
+ Size += NodeLength;
+
+ //
+ // Validate next node before touch it.
+ //
+ if (Size > MaxSize - END_DEVICE_PATH_LENGTH ) {
+ return FALSE;
}
if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {