[edk2] [PATCH 4/5] BaseTools/C/Common: Fix potential null pointer dereference

Hao Wu posted 5 patches 6 years, 11 months ago
[edk2] [PATCH 4/5] BaseTools/C/Common: Fix potential null pointer dereference
Posted by Hao Wu 6 years, 11 months ago
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 BaseTools/Source/C/Common/PcdValueCommon.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c b/BaseTools/Source/C/Common/PcdValueCommon.c
index 611085cd2d..4b4f137ecf 100644
--- a/BaseTools/Source/C/Common/PcdValueCommon.c
+++ b/BaseTools/Source/C/Common/PcdValueCommon.c
@@ -72,6 +72,9 @@ Returns:
   CHAR8  *Token;
 
   Token = malloc (TokenEnd - TokenStart + 1);
+  if (Token == NULL) {
+    return;
+  }
   memcpy (Token, &FileBuffer[TokenStart], TokenEnd - TokenStart);
   Token[TokenEnd - TokenStart] = 0;
   switch (TokenIndex) {
@@ -333,6 +336,10 @@ Returns:
       Value = End + 1;
     }
     Buffer = malloc(*Size);
+    if (Buffer == NULL) {
+      *Size = 0;
+      return NULL;
+    }
     Value = &PcdList[Index].Value[1];
     for (*Size = 0, Buffer[*Size] = (UINT8) strtoul(Value, &End, 16); Value != End; *Size = *Size + 1, Buffer[*Size] = (UINT8) strtoul(Value, &End, 16)) {
       Value = End + 1;
-- 
2.12.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel