BaseTools/C/Common: Fix potential null pointer dereference

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Hao Wu 2018-01-03 19:30:36 +08:00
parent 46cced287e
commit 66329d53bd
1 changed files with 7 additions and 0 deletions

View File

@ -72,6 +72,9 @@ Returns:
CHAR8 *Token; CHAR8 *Token;
Token = malloc (TokenEnd - TokenStart + 1); Token = malloc (TokenEnd - TokenStart + 1);
if (Token == NULL) {
return;
}
memcpy (Token, &FileBuffer[TokenStart], TokenEnd - TokenStart); memcpy (Token, &FileBuffer[TokenStart], TokenEnd - TokenStart);
Token[TokenEnd - TokenStart] = 0; Token[TokenEnd - TokenStart] = 0;
switch (TokenIndex) { switch (TokenIndex) {
@ -333,6 +336,10 @@ Returns:
Value = End + 1; Value = End + 1;
} }
Buffer = malloc(*Size); Buffer = malloc(*Size);
if (Buffer == NULL) {
*Size = 0;
return NULL;
}
Value = &PcdList[Index].Value[1]; 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)) { 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; Value = End + 1;