Skip to content

Commit

Permalink
Fix remove_dxes_except corner cases
Browse files Browse the repository at this point in the history
The parseBlackList function create a regex with several string option,
FindFilePredicate encapsulate it to match whole word only but we have
to take care of the blacklist case where the regex string include '|'.

Signed-off-by: Julien Viard de Galbert <[email protected]>
  • Loading branch information
JulienVdG committed Feb 18, 2019
1 parent 7ea5f5c commit a33c73f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/visitors/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func FindFileTypePredicate(t uefi.FVFileType) FindPredicate {

// FindFilePredicate is a generic predicate for searching files and UI sections only.
func FindFilePredicate(r string) (func(f uefi.Firmware) bool, error) {
searchRE, err := regexp.Compile("^" + r + "$")
searchRE, err := regexp.Compile("^(" + r + ")$")
if err != nil {
return nil, err
}
ciRE, err := regexp.Compile("^(?i)" + r + "$")
ciRE, err := regexp.Compile("^(?i)(" + r + ")$")
if err != nil {
return nil, err
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/visitors/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,49 @@ func TestRemoveExcept(t *testing.T) {
}

}

func TestRemoveExceptBlackList(t *testing.T) {
// The following blacklist contains corner case:
// - start, mid or end of existing names but no full name
// - start, mid or end of existing GUID but no full GUID
// so it should behave as an empty blacklist, ie remove all
var blacklists = []string{
"INEXISTING_FILENAME\nINEXISTING_FILENAME2",
"Isa\nDisk\nDxe",
"D6A2CB7F\n11E3\n9920A733700A",
}
for _, blacklist := range blacklists {
f := parseImage(t)

blackListRegex, err := parseBlackList("(embedded)", blacklist)
if err != nil {
t.Fatal(err)
}

pred, err := FindFilePredicate(blackListRegex)
if err != nil {
t.Fatal(err)
}
remove := &Remove{
Predicate: pred,
RemoveDxes: true,
}
if err := remove.Run(f); err != nil {
t.Fatal(err)
}

// We expect no more dxe drivers since we only kept the core.
count := &Count{}
if err := count.Run(f); err != nil {
t.Fatal(err)
}
dxeCount := count.FileTypeCount["EFI_FV_FILETYPE_DRIVER"]
coreCount := count.FileTypeCount["EFI_FV_FILETYPE_DXE_CORE"]
if dxeCount != 0 {
t.Errorf("expected no more drivers, got %v", dxeCount)
}
if coreCount != 0 {
t.Errorf("expected no more dxecore, got %v", coreCount)
}
}
}

0 comments on commit a33c73f

Please sign in to comment.