[pve-devel] applied: [PATCH storage] fix #2099: escape systemd path names in mount unit

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Feb 20 16:32:57 CET 2019


On 2/20/19 4:04 PM, Dominik Csapak wrote:
> we only allow '-' '_' and '.' int storage-ids and names,
> and we do not need to escape '_' and '.' (see man 5 systemd.unit)
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  PVE/API2/Disks/Directory.pm | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 

applied, with a comment followup to note that we do not adhere systemd-escape
rules fully, and another one to adhere a bit more to them  ^^
Thanks!

> diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm
> index 02cc72a..630d1cd 100644
> --- a/PVE/API2/Disks/Directory.pm
> +++ b/PVE/API2/Disks/Directory.pm
> @@ -87,6 +87,22 @@ my $write_ini = sub {
>      file_set_contents($filename, $content);
>  };
>  
> +sub systemd_escape {
> +    my ($val) = @_;
> +
> +    $val =~ s/\-/\\x2d/g;
> +
> +    return $val;
> +}
> +
> +sub systemd_unescape {
> +    my ($val) = @_;
> +
> +    $val =~ s/\\x([a-fA-F0-9]{2})/chr(hex($1))/eg;
> +
> +    return $val;
> +}
> +
>  __PACKAGE__->register_method ({
>      name => 'index',
>      path => '',
> @@ -138,6 +154,7 @@ __PACKAGE__->register_method ({
>  
>  	dir_glob_foreach('/etc/systemd/system', '^mnt-pve-(.+)\.mount$', sub {
>  	    my ($filename, $storid) = @_;
> +	    $storid = systemd_unescape($storid);
>  
>  	    my $unitfile = "/etc/systemd/system/$filename";
>  	    my $unit = $read_ini->($unitfile);
> @@ -206,7 +223,7 @@ __PACKAGE__->register_method ({
>  
>  	my $worker = sub {
>  	    my $path = "/mnt/pve/$name";
> -	    my $mountunitname = "mnt-pve-$name.mount";
> +	    my $mountunitname = "mnt-pve-".systemd_escape($name).".mount";
>  	    my $mountunitpath = "/etc/systemd/system/$mountunitname";
>  
>  	    PVE::Diskmanage::locked_disk_action(sub {
> 





More information about the pve-devel mailing list