From 6917710064ca57f0e4997987c1af0c909672ac12 Mon Sep 17 00:00:00 2001 From: Vignesh Raman Date: Tue, 27 Jul 2021 11:13:46 +0530 Subject: [PATCH] actions/image-partition: check filesystem label length in verify stage The filesystem label can be up to 11 characters long for vfat, 16 characters long for ext2/3/4, 255 characters long for btrfs, 512 characters long for hfs/hfsplus and 12 characters long for xfs. Any longer labels will be automatically truncated. Fixes: #251 Suggested-by: Christopher Obbard Signed-off-by: Vignesh Raman --- actions/image_partition_action.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index 4e967d17..f74ee9f5 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -76,7 +76,8 @@ to the `name` property of the partition. May only be used for GPT partitions. - fslabel -- Sets the volume name (label) of the filesystem. Defaults to the `name` property of the partition. The filesystem label can be up to 11 characters long for vfat, 16 characters long for ext2/3/4, 255 characters long for btrfs, -512 characters long for hfs/hfsplus and 12 characters long for xfs. +512 characters long for hfs/hfsplus and 12 characters long for xfs. Any longer +labels will be automatically truncated. - parttype -- set the partition type in the partition table. The string should be in a hexadecimal format (2-characters) for msdos partition tables and GUID format @@ -621,9 +622,31 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error { } if i.PartitionType == "gpt" { + var maxLength int = 0 if p.FSLabel == "" { p.FSLabel = p.Name } + + switch p.FS { + case "vfat": + maxLength = 11 + case "ext2", "ext3", "ext4": + maxLength = 16 + case "btrfs": + maxLength = 255 + case "f2fs": + maxLength = 512 + case "hfs", "hfsplus": + maxLength = 255 + case "xfs": + maxLength = 12 + } + + if maxLength > 0 && len(p.FSLabel) > maxLength { + truncated := p.FSLabel[0:maxLength] + log.Printf("Warning: fs label for %s '%s' is too long; truncated to '%s'", p.Name, p.FSLabel, truncated) + p.FSLabel = truncated + } } if len(p.FSUUID) > 0 {