Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 6b45f845 authored by Jihoon Kang's avatar Jihoon Kang Committed by Michael Bestas
Browse files

Disallow prebuilt_root module type from setting Dsts property

...to prevent prebuilt_root module type from installing files in
arbitrary locations within the partition.

Test: m nothing --no-skip-soong-tests
Bug: 402903576
Change-Id: I6999c3256668bbe738a38abc4accc05e390511ba
parent cc1c4aaf
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -105,12 +105,6 @@ type PrebuiltEtcProperties struct {
	// set. May use globs in filenames.
	Srcs proptools.Configurable[[]string] `android:"path,arch_variant"`

	// Destination files of this prebuilt. Requires srcs to be used and causes srcs not to implicitly
	// set filename_from_src. This can be used to install each source file to a different directory
	// and/or change filenames when files are installed. Must be exactly one entry per source file,
	// which means care must be taken if srcs has globs.
	Dsts proptools.Configurable[[]string] `android:"path,arch_variant"`

	// Optional name for the installed file. If unspecified, name of the module is used as the file
	// name. Only available when using a single source (src).
	Filename *string `android:"arch_variant"`
@@ -149,6 +143,20 @@ type PrebuiltEtcProperties struct {
	Oem_specific *bool `android:"arch_variant"`
}

// Dsts is useful in that it allows prebuilt_* modules to easily map the source files to the
// install path within the partition. Dsts values are allowed to contain filepath separator
// so that the source files can be installed in subdirectories within the partition.
// However, this functionality should not be supported for prebuilt_root module type, as it
// allows the module to install to any arbitrary location. Thus, this property is defined in
// a separate struct so that it's not available to be set in prebuilt_root module type.
type PrebuiltDstsProperties struct {
	// Destination files of this prebuilt. Requires srcs to be used and causes srcs not to implicitly
	// set filename_from_src. This can be used to install each source file to a different directory
	// and/or change filenames when files are installed. Must be exactly one entry per source file,
	// which means care must be taken if srcs has globs.
	Dsts proptools.Configurable[[]string] `android:"path,arch_variant"`
}

type prebuiltSubdirProperties struct {
	// Optional subdirectory under which this file is installed into, cannot be specified with
	// relative_install_path, prefer relative_install_path.
@@ -184,6 +192,8 @@ type PrebuiltEtc struct {

	properties PrebuiltEtcProperties

	dstsProperties PrebuiltDstsProperties

	// rootProperties is used to return the value of the InstallInRoot() method. Currently, only
	// prebuilt_avb and prebuilt_root modules use this.
	rootProperties prebuiltRootProperties
@@ -374,7 +384,7 @@ func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	if srcProperty.IsPresent() && len(srcsProperty) > 0 {
		ctx.PropertyErrorf("src", "src is set. Cannot set srcs")
	}
	dstsProperty := p.properties.Dsts.GetOrDefault(ctx, nil)
	dstsProperty := p.dstsProperties.Dsts.GetOrDefault(ctx, nil)
	if len(dstsProperty) > 0 && len(srcsProperty) == 0 {
		ctx.PropertyErrorf("dsts", "dsts is set. Must use srcs")
	}
@@ -581,6 +591,7 @@ func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
	p.AddProperties(&p.properties)
	p.AddProperties(&p.subdirProperties)
	p.AddProperties(&p.rootProperties)
	p.AddProperties(&p.dstsProperties)
}

func InitPrebuiltRootModule(p *PrebuiltEtc) {
@@ -592,6 +603,7 @@ func InitPrebuiltRootModule(p *PrebuiltEtc) {
func InitPrebuiltAvbModule(p *PrebuiltEtc) {
	p.installDirBase = "avb"
	p.AddProperties(&p.properties)
	p.AddProperties(&p.dstsProperties)
	p.rootProperties.Install_in_root = proptools.BoolPtr(true)
}

+28 −8
Original line number Diff line number Diff line
@@ -349,15 +349,25 @@ func TestPrebuiltEtcModuleGen(t *testing.T) {
	eval := generatedModule0.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext))
	android.AssertBoolEquals(
		t,
		"module expected to set correct srcs and dsts properties",
		"module expected to set correct srcs property",
		true,
		checkModuleProp(generatedModule0, func(actual interface{}) bool {
			if p, ok := actual.(*etc.PrebuiltEtcProperties); ok {
				srcs := p.Srcs.GetOrDefault(eval, nil)
				dsts := p.Dsts.GetOrDefault(eval, nil)
				return len(srcs) == 1 &&
					srcs[0] == "apns-full-conf.xml" &&
					len(dsts) == 1 &&
					srcs[0] == "apns-full-conf.xml"
			}
			return false
		}),
	)
	android.AssertBoolEquals(
		t,
		"module expected to set correct dsts property",
		true,
		checkModuleProp(generatedModule0, func(actual interface{}) bool {
			if p, ok := actual.(*etc.PrebuiltDstsProperties); ok {
				dsts := p.Dsts.GetOrDefault(eval, nil)
				return len(dsts) == 1 &&
					dsts[0] == "apns-conf.xml"
			}
			return false
@@ -368,15 +378,25 @@ func TestPrebuiltEtcModuleGen(t *testing.T) {
	eval = generatedModule1.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext))
	android.AssertBoolEquals(
		t,
		"module expected to set correct srcs and dsts properties",
		"module expected to set correct srcs property",
		true,
		checkModuleProp(generatedModule1, func(actual interface{}) bool {
			if p, ok := actual.(*etc.PrebuiltEtcProperties); ok {
				srcs := p.Srcs.GetOrDefault(eval, nil)
				dsts := p.Dsts.GetOrDefault(eval, nil)
				return len(srcs) == 1 &&
					srcs[0] == "apns-full-conf.xml" &&
					len(dsts) == 1 &&
					srcs[0] == "apns-full-conf.xml"
			}
			return false
		}),
	)
	android.AssertBoolEquals(
		t,
		"module expected to set correct dsts property",
		true,
		checkModuleProp(generatedModule1, func(actual interface{}) bool {
			if p, ok := actual.(*etc.PrebuiltDstsProperties); ok {
				dsts := p.Dsts.GetOrDefault(eval, nil)
				return len(dsts) == 1 &&
					dsts[0] == "apns-conf-2.xml"
			}
			return false
+6 −4
Original line number Diff line number Diff line
@@ -164,7 +164,6 @@ type prebuiltModuleProperties struct {
	Ramdisk             *bool

	Srcs []string
	Dsts []string

	No_full_install *bool

@@ -357,11 +356,14 @@ func createPrebuiltEtcModulesInDirectory(ctx android.LoadHookContext, partition,
				moduleFactory = etc.PrebuiltAnyFactory
			}
			modulePropsPtr.Srcs = srcBaseFiles
			dsts := []string{}
			dsts := proptools.NewConfigurable[[]string](nil, nil)
			for _, installBaseFile := range installBaseFiles {
				dsts = append(dsts, filepath.Join(relDestDirFromInstallDirBase, installBaseFile))
				dsts.AppendSimpleValue([]string{filepath.Join(relDestDirFromInstallDirBase, installBaseFile)})
			}
			modulePropsPtr.Dsts = dsts

			propsList = append(propsList, &etc.PrebuiltDstsProperties{
				Dsts: dsts,
			})
		}

		ctx.CreateModuleInDirectory(moduleFactory, srcDir, propsList...)