Skip to content

Commit

Permalink
Ext4Pkg: Check that source file is directory in Ext4OpenInternal
Browse files Browse the repository at this point in the history
This check already present in the while loop below, but absent for cases
when input file is nameless, so to handle assertion in Ext4ReadFile we
need to add it at the top of function

Cc: Marvin Häuser <[email protected]>
Cc: Pedro Falcato <[email protected]>
Cc: Vitaly Cheptsov <[email protected]>
Fixes: d9ceedc ("Ext4Pkg: Add Ext4Dxe driver.")
Signed-off-by: Savva Mitrofanov <[email protected]>
Reviewed-by: Pedro Falcato <[email protected]>
Reviewed-by: Marvin Häuser <[email protected]>
  • Loading branch information
savvamitrofanov authored and heatd committed Feb 8, 2023
1 parent 92065de commit d0cd979
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Features/Ext4Pkg/Ext4Dxe/File.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ Ext4OpenInternal (
Level = 0;

DEBUG ((DEBUG_FS, "[ext4] Ext4OpenInternal %s\n", FileName));

if (!Ext4FileIsDir (Current)) {
return EFI_INVALID_PARAMETER;
}

// If the path starts with a backslash, we treat the root directory as the base directory
if (FileName[0] == L'\\') {
FileName++;
Expand All @@ -219,6 +224,10 @@ Ext4OpenInternal (
return EFI_ACCESS_DENIED;
}

if (!Ext4FileIsDir (Current)) {
return EFI_INVALID_PARAMETER;
}

// Discard leading path separators
while (FileName[0] == L'\\') {
FileName++;
Expand All @@ -242,10 +251,6 @@ Ext4OpenInternal (

DEBUG ((DEBUG_FS, "[ext4] Opening %s\n", PathSegment));

if (!Ext4FileIsDir (Current)) {
return EFI_INVALID_PARAMETER;
}

if (!Ext4IsLastPathSegment (FileName)) {
if (!Ext4DirCanLookup (Current)) {
return EFI_ACCESS_DENIED;
Expand Down

0 comments on commit d0cd979

Please sign in to comment.