From 190e3e0e42c3f7fd7ad4307594052045034ccbe7 Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Thu, 8 Feb 2024 04:44:56 +0000 Subject: [PATCH] files: fix invalid syntax cases Signed-off-by: Chris Koch --- uroot/uroot.go | 7 ++++++- uroot/uroot_test.go | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/uroot/uroot.go b/uroot/uroot.go index 3e7f6bc..03dcbf5 100644 --- a/uroot/uroot.go +++ b/uroot/uroot.go @@ -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 { diff --git a/uroot/uroot_test.go b/uroot/uroot_test.go index d5e9a90..d74bba6 100644 --- a/uroot/uroot_test.go +++ b/uroot/uroot_test.go @@ -150,7 +150,6 @@ func TestCreateInitramfs(t *testing.T) { itest.IsEmpty{}, }, }, - /* TODO: case is broken. { name: "files invalid syntax 1", opts: Opts{ @@ -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{ @@ -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",