mirror of https://github.com/acidanthera/audk.git
MdePkg/PiFirmwareFile: fix undefined behavior in FFS_FILE_SIZE
Accessing "EFI_FFS_FILE_HEADER.Size", which is of type UINT8[3], through a (UINT32*), is undefined behavior. Fix it by accessing the array elements individually. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1710 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
parent
d3b3ee09a6
commit
1fd227dd26
|
@ -179,8 +179,15 @@ typedef struct {
|
|||
#define IS_FFS_FILE2(FfsFileHeaderPtr) \
|
||||
(((((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Attributes) & FFS_ATTRIB_LARGE_FILE) == FFS_ATTRIB_LARGE_FILE)
|
||||
|
||||
#define FFS_FILE_SIZE(FfsFileHeaderPtr) \
|
||||
((UINT32) (*((UINT32 *) ((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Size) & 0x00ffffff))
|
||||
///
|
||||
/// The argument passed as the FfsFileHeaderPtr parameter to the
|
||||
/// FFS_FILE_SIZE() function-like macro below must not have side effects:
|
||||
/// FfsFileHeaderPtr is evaluated multiple times.
|
||||
///
|
||||
#define FFS_FILE_SIZE(FfsFileHeaderPtr) ((UINT32) ( \
|
||||
(((EFI_FFS_FILE_HEADER *) (UINTN) (FfsFileHeaderPtr))->Size[0] ) | \
|
||||
(((EFI_FFS_FILE_HEADER *) (UINTN) (FfsFileHeaderPtr))->Size[1] << 8) | \
|
||||
(((EFI_FFS_FILE_HEADER *) (UINTN) (FfsFileHeaderPtr))->Size[2] << 16)))
|
||||
|
||||
#define FFS_FILE2_SIZE(FfsFileHeaderPtr) \
|
||||
((UINT32) (((EFI_FFS_FILE_HEADER2 *) (UINTN) FfsFileHeaderPtr)->ExtendedSize))
|
||||
|
|
Loading…
Reference in New Issue