Skip to content

Commit

Permalink
files: fix invalid syntax cases
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Feb 8, 2024
1 parent dd94bfe commit 190e3e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 6 additions & 1 deletion uroot/uroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ func ParseExtraFiles(logger ulog.Logger, archive *initramfs.Files, extraFiles []
var src, dst string
parts := strings.SplitN(file, ":", 2)
if len(parts) == 2 {
// treat the entry with the new src:dst syntax
if len(parts[0]) == 0 {
return fmt.Errorf("%w: invalid extra files %q", os.ErrInvalid, file)
}
if len(parts[1]) == 0 {
return fmt.Errorf("%w: invalid extra files %q", os.ErrInvalid, file)
}
src = filepath.Clean(parts[0])
dst = filepath.Clean(parts[1])
} else {
Expand Down
8 changes: 2 additions & 6 deletions uroot/uroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func TestCreateInitramfs(t *testing.T) {
itest.IsEmpty{},
},
},
/* TODO: case is broken.
{
name: "files invalid syntax 1",
opts: Opts{
Expand All @@ -159,13 +158,11 @@ func TestCreateInitramfs(t *testing.T) {
":etc/somefile",
},
},
//errs: []error{os.ErrExist},
errs: []error{os.ErrInvalid},
validators: []itest.ArchiveValidator{
itest.IsEmpty{},
},
},
*/
/* TODO: case is broken.
{
name: "files invalid syntax 2",
opts: Opts{
Expand All @@ -174,12 +171,11 @@ func TestCreateInitramfs(t *testing.T) {
somefile + ":",
},
},
//errs: []error{os.ErrExist},
errs: []error{os.ErrInvalid},
validators: []itest.ArchiveValidator{
itest.IsEmpty{},
},
},
*/
// TODO: files are directories.
{
name: "file conflicts with init",
Expand Down

0 comments on commit 190e3e0

Please sign in to comment.