diff options
author | 2025-03-12 22:24:52 +0000 | |
---|---|---|
committer | 2025-03-13 17:46:37 +0000 | |
commit | f729d2e617bef827503888c76383ab9e6bf7c8d7 (patch) | |
tree | c68efe5a063ae5301a3027f1d3770986fac5ec5b | |
parent | 002767b80d8962e4ba882ca739871874556efdd8 (diff) |
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
-rw-r--r-- | etc/prebuilt_etc.go | 26 | ||||
-rw-r--r-- | fsgen/filesystem_creator_test.go | 36 | ||||
-rw-r--r-- | fsgen/prebuilt_etc_modules_gen.go | 10 |
3 files changed, 53 insertions, 19 deletions
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index f2bf0d243..68bffd4d1 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -114,12 +114,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"` @@ -158,6 +152,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. @@ -193,6 +201,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 @@ -383,7 +393,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") } @@ -611,6 +621,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) { @@ -622,6 +633,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) } diff --git a/fsgen/filesystem_creator_test.go b/fsgen/filesystem_creator_test.go index ba40f3f5e..81236a0a1 100644 --- a/fsgen/filesystem_creator_test.go +++ b/fsgen/filesystem_creator_test.go @@ -366,15 +366,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 @@ -385,15 +395,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 diff --git a/fsgen/prebuilt_etc_modules_gen.go b/fsgen/prebuilt_etc_modules_gen.go index 0adf7a1e3..df945b33f 100644 --- a/fsgen/prebuilt_etc_modules_gen.go +++ b/fsgen/prebuilt_etc_modules_gen.go @@ -164,7 +164,6 @@ type prebuiltModuleProperties struct { Ramdisk *bool Srcs []string - Dsts []string No_full_install *bool @@ -355,11 +354,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...) |