Skip to content

Commit

Permalink
Added check if requested overridevalidation file is not contained in …
Browse files Browse the repository at this point in the history
…a Package (#256)

Fixes #255

Please ensure you have read the [contribution
docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior
to submitting the pull request. In particular,
[pull request
guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices).

OverrideValidation can run on files that are not contained inside of a
Edk2 Package path. These files, when passed to GetContainingPackage(),
will return none type.

Adding a check that if the GetContainingPackage returns none type, uses
os.path.relpath to get a relative path from the base of the workspace
passed into the tool.

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [ ] 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, ...

Tested locally on a system by passing in
"MU_BASECORE/BaseTools/Conf/tools_def.template".

N/A
  • Loading branch information
apop5 authored and kenlautner committed May 9, 2023
1 parent 26a8bd1 commit 4aa106d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .pytool/CISettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def GetActiveScopes(self):
"STUART_CODEQL_AUDIT_ONLY",
"TRUE",
"Set in CISettings.py")
shell_environment.GetBuildVars().SetValue(
"STUART_CODEQL_FILTER_FILES",
os.path.join(self.GetWorkspaceRoot(),
"CodeQlFilters.yml"),
"Set in CISettings.py")
except NameError:
pass

Expand Down
8 changes: 7 additions & 1 deletion BaseTools/Plugin/OverrideValidation/OverrideValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,13 @@ def path_parse():
# Generate and print the override for pasting into the file.
# Use absolute module path to find package path
pkg_path = pathtool.GetContainingPackage(Paths.TargetPath)
rel_path = Paths.TargetPath[Paths.TargetPath.find(pkg_path):]
if pkg_path is not None:
rel_path = Paths.TargetPath[Paths.TargetPath.find(pkg_path):]
else:
rel_path = pathtool.GetEdk2RelativePathFromAbsolutePath(Paths.TargetPath)
if not rel_path:
print(f"{Paths.TargetPath} is invalid for this workspace.")
sys.exit(1)

rel_path = rel_path.replace('\\', '/')
mod_hash = ModuleHashCal(Paths.TargetPath)
Expand Down
24 changes: 24 additions & 0 deletions CodeQlFilters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## @file
# CodeQL Result Filters for Packages in Mu Basecore
#
# Note: Packages that use Mu Basecore can reuse this file to quickly pick up the
# same filters applied to results in the Mu Basecore repo.
#
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

{
"Filters": [
"-MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c:SM02311",
"-MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c:SM02311",
"-MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c:SM02311",
"-MdeModulePkg/Universal/Disk/UdfDxe/FileName.c:cpp/uselesstest",
"-MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c:cpp/uselesstest",
"-MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c:cpp/uselesstest",
"-MdeModulePkg/Core/Pei/Ppi/Ppi.c:cpp/overflow-buffer",
"-ShellPkg/Application/Shell/ShellManParser.c:cpp/redundant-null-check-param",
"-ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Aest/AestParser.c:cpp/overflow-buffer",
"-ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c:cpp/overflow-buffer"
]
}

0 comments on commit 4aa106d

Please sign in to comment.