From 7529a26b4d844f1fc0e164ccd2a83a12f98476a5 Mon Sep 17 00:00:00 2001 From: Mark D Horn Date: Fri, 23 Aug 2019 14:51:29 -0700 Subject: [PATCH] storage: locale: Validate advanced mounts Ensure that the advanced extra mount points are absolute paths and correctly formed. Signed-off-by: Mark D Horn --- locale/en_US/LC_MESSAGES/clr-installer.po | 4 ++ locale/es_MX/LC_MESSAGES/clr-installer.po | 4 ++ locale/zh_CN/LC_MESSAGES/clr-installer.po | 4 ++ storage/ops.go | 58 ++++++++++++++++------- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/locale/en_US/LC_MESSAGES/clr-installer.po b/locale/en_US/LC_MESSAGES/clr-installer.po index 9bf50313..82e3809d 100644 --- a/locale/en_US/LC_MESSAGES/clr-installer.po +++ b/locale/en_US/LC_MESSAGES/clr-installer.po @@ -338,6 +338,10 @@ msgstr "%s must be %s" msgid "Found multiple %s partition labels" msgstr "Found multiple %s partition labels" +#, c-format +msgid "Found invalid %s partition label" +msgstr "Found invalid %s partition label" + #, c-format msgid "Encryption of %s is not supported" msgstr "Encryption of %s is not supported" diff --git a/locale/es_MX/LC_MESSAGES/clr-installer.po b/locale/es_MX/LC_MESSAGES/clr-installer.po index f82d7968..a30c315a 100644 --- a/locale/es_MX/LC_MESSAGES/clr-installer.po +++ b/locale/es_MX/LC_MESSAGES/clr-installer.po @@ -338,6 +338,10 @@ msgstr "MX: %s must be %s" msgid "Found multiple %s partition labels" msgstr "MX: Found multiple %s partition labels" +#, c-format +msgid "Found invalid %s partition label" +msgstr "MX: Found invalid %s partition label" + #, c-format msgid "Encryption of %s is not supported" msgstr "MX: Encryption of %s is not supported" diff --git a/locale/zh_CN/LC_MESSAGES/clr-installer.po b/locale/zh_CN/LC_MESSAGES/clr-installer.po index eb48bc51..6c7cd2e8 100644 --- a/locale/zh_CN/LC_MESSAGES/clr-installer.po +++ b/locale/zh_CN/LC_MESSAGES/clr-installer.po @@ -338,6 +338,10 @@ msgstr "CN: %s must be %s" msgid "Found multiple %s partition labels" msgstr "CN: Found multiple %s partition labels" +#, c-format +msgid "Found invalid %s partition label" +msgstr "CN: Found invalid %s partition label" + #, c-format msgid "Encryption of %s is not supported" msgstr "CN: Encryption of %s is not supported" diff --git a/storage/ops.go b/storage/ops.go index 8978b6b4..43030960 100644 --- a/storage/ops.go +++ b/storage/ops.go @@ -1415,7 +1415,6 @@ func FindAdvancedInstallTargets(medias []*BlockDevice) []*BlockDevice { for _, ch := range installBlockDevice.Children { clrFound := false - clrMountFound := false label := ch.PartitionLabel if label != "" { @@ -1424,19 +1423,6 @@ func FindAdvancedInstallTargets(medias []*BlockDevice) []*BlockDevice { for _, part := range strings.Split(label, "_") { lowerPart := strings.ToLower(part) - if clrMountFound { - log.Debug("AdvancedPartitioning: Extra mount %q for %s", part, ch.Name) - ch.MountPoint = part - if ch.FsType == "" { - log.Debug("AdvancedPartitioning: No FsType set for %s, defaulting to %s", ch.Name, defaultFsType) - ch.FsType = defaultFsType - log.Debug("AdvancedPartitioning: Forcing Format partition %s enabled", ch.Name) - ch.FormatPartition = true - } - clrAdded = true - clrMountFound = false - continue - } if !clrFound { if lowerPart == "clr" { @@ -1481,8 +1467,23 @@ func FindAdvancedInstallTargets(medias []*BlockDevice) []*BlockDevice { ch.FormatPartition = true } case "mnt": - clrMountFound = true - log.Debug("FindAdvancedInstallTargets: Extra mount found %s", ch.Name) + mntParts := strings.Split(label, "MNT_") + if len(mntParts) == 2 { + path := filepath.Clean(mntParts[1]) + if filepath.IsAbs(path) { + log.Debug("AdvancedPartitioning: Extra mount %q for %s", path, ch.Name) + + ch.MountPoint = path + if ch.FsType == "" { + log.Debug("AdvancedPartitioning: No FsType set for %s, defaulting to %s", ch.Name, defaultFsType) + ch.FsType = defaultFsType + log.Debug("AdvancedPartitioning: Forcing Format partition %s enabled", ch.Name) + ch.FormatPartition = true + } + clrAdded = true + } + } + break case "e": if ch.MountPoint == "/boot" { log.Warning("AdvancedPartitioning: /boot can no be encrypted, skipping") @@ -1634,6 +1635,31 @@ func validateAdvancedPartitions(rootSize uint64, medias []*BlockDevice) []string results = append(results, warning) log.Warning("validateAdvancedPartitions: %s %+v", warning, ch) } + case "mnt": + failed := false + warning := utils.Locale.Get("Found invalid %s partition label", label) + + mntParts := strings.Split(label, "MNT_") + if len(mntParts) != 2 { + failed = true + log.Warning("validateAdvancedPartitions: %s %+v (%s)", warning, ch, "too many parts") + } + + if !strings.HasPrefix(mntParts[1], "/") { + failed = true + log.Warning("validateAdvancedPartitions: %s %+v (%s)", warning, ch, "must start with '/'") + } + + path := filepath.Clean(mntParts[1]) + if !filepath.IsAbs(path) { + failed = true + log.Warning("validateAdvancedPartitions: %s %+v (%s)", warning, ch, "must be an absolute path") + } + + if failed { + results = append(results, warning) + } + break case "e": if strings.HasPrefix(strings.ToLower(ch.PartitionLabel), "clr_boot") { warning := utils.Locale.Get("Encryption of %s is not supported", "CLR_BOOT")