From 9242b0bea18555d6d1db8012d62912aae0a23e81 Mon Sep 17 00:00:00 2001 From: William Wilson Date: Mon, 31 Jan 2022 09:09:13 -0600 Subject: [PATCH] Use strutil.shlex rather than strings --- osutil/mkfs/mkfs.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osutil/mkfs/mkfs.go b/osutil/mkfs/mkfs.go index e62116d4717..d2f48bb1107 100644 --- a/osutil/mkfs/mkfs.go +++ b/osutil/mkfs/mkfs.go @@ -25,10 +25,10 @@ import ( "os" "os/exec" "path/filepath" - "strings" "github.com/snapcore/snapd/gadget/quantity" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/strutil/shlex" ) // MakeFunc defines a function signature that is used by all of the mkfs. @@ -111,8 +111,14 @@ func mkfsExt4(img, label, contentsRootDir string, deviceSize, sectorSize quantit if fakerootFlags != "" { // When executing fakeroot from a classic confinement snap the location of // libfakeroot must be specified, or else it will be loaded from the host system - fakerootArgs := append(strings.Split(fakerootFlags, " "), "--") - mkfsArgs = append(fakerootArgs, mkfsArgs...) + flags, err := shlex.Split(fakerootFlags) + if err != nil { + return fmt.Errorf("cannot split fakeroot command: %v", err) + } + if len(fakerootFlags) > 0 { + fakerootArgs := append(flags, "--") + mkfsArgs = append(fakerootArgs, mkfsArgs...) + } } cmd = exec.Command("fakeroot", mkfsArgs...) } else {