Skip to content

Commit

Permalink
Fix section data length always 4 bytes larger than real data (#752)
Browse files Browse the repository at this point in the history
## Description

This change fixed an issue where the returned section data length is
always 4 bytes larger than the real section. This would cause an issue
where the caller could read into the final 4 bytes which is invalid data
region.

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

This is verified on QEMU Q35 platform and booted to UEFI shell.

## Integration Instructions

N/A
  • Loading branch information
kuqin12 authored Feb 28, 2024
1 parent e628e05 commit b778f1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion StandaloneMmPkg/Include/Library/FvLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ FindFfsSectionInSections (
@param FfsFileHeader Pointer to the current file to search.
@param SectionData Pointer to the Section matching SectionType in FfsFileHeader.
NULL if section not found
@param SectionDataSize The size of SectionData
@param SectionDataSize The size of SectionData, excluding the section header.
@retval EFI_NOT_FOUND No files matching the search criteria were found
@retval EFI_SUCCESS
Expand Down
6 changes: 3 additions & 3 deletions StandaloneMmPkg/Library/FvLib/FvLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ FfsFindSection (
@param FfsFileHeader Pointer to the current file to search.
@param SectionData Pointer to the Section matching SectionType in FfsFileHeader.
NULL if section not found
@param SectionDataSize The size of SectionData
@param SectionDataSize The size of SectionData, excluding the section header.
@retval EFI_NOT_FOUND No files matching the search criteria were found
@retval EFI_SUCCESS
Expand Down Expand Up @@ -380,10 +380,10 @@ FfsFindSectionData (
if (Section->Type == SectionType) {
if (IS_SECTION2 (Section)) {
*SectionData = (VOID *)((EFI_COMMON_SECTION_HEADER2 *)Section + 1);
*SectionDataSize = SECTION2_SIZE (Section);
*SectionDataSize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
} else {
*SectionData = (VOID *)(Section + 1);
*SectionDataSize = SECTION_SIZE (Section);
*SectionDataSize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
}

return EFI_SUCCESS;
Expand Down

0 comments on commit b778f1e

Please sign in to comment.