MdeModulePkg/Spi: Solving potential null ptr deref. in SpiNorFlashJedecSfdp
The pointer `Instance->SfdpBasicFlash` can be used before initializing.
Example code flow:
- CreateSpiNorFlashSfdpInstance: Allocate pool for `Instance`
- InitialSpiNorFlashSfdpInstance
- ReadSfdp
- ReadSfdpHeader
- FillWriteBuffer: Dereferencing
`Instance->SfdpBasicFlash`
- ReadSfdpBasicParameterTable: Allocate pool for
`Instance->SfdpBasicFlash`
Check both `Instance` and `Instance->SfdpBasicFlash` should have
a non null value before dereferencing it. Otherwise use the defaut
value 0.
Also terminate the function if `Instance` or `WriteBuffer` is NULL.
Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
This commit is contained in:
@@ -48,7 +48,17 @@ FillWriteBuffer (
|
||||
UINT32 Index;
|
||||
UINT8 SfdpAddressBytes;
|
||||
|
||||
SfdpAddressBytes = (UINT8)Instance->SfdpBasicFlash->AddressBytes;
|
||||
if ((Instance == NULL) || (WriteBuffer == NULL)) {
|
||||
ASSERT (Instance != NULL);
|
||||
ASSERT (WriteBuffer != NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Instance->SfdpBasicFlash == NULL) {
|
||||
SfdpAddressBytes = 0;
|
||||
} else {
|
||||
SfdpAddressBytes = (UINT8)Instance->SfdpBasicFlash->AddressBytes;
|
||||
}
|
||||
|
||||
// Copy Opcode into Write Buffer
|
||||
Instance->SpiTransactionWriteBuffer[0] = Opcode;
|
||||
|
||||
Reference in New Issue
Block a user