From 35c5a0b279b99f30430f4a8e5092c7b2f1234316 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Thu, 19 Nov 2015 13:55:58 -0600 Subject: [PATCH] Protect mountpoint from relative paths and duplicate pathsep Use os.path.realpath() to clean up any path manipulations Signed-off-by: Ryan Harper --- subiquity/models/filesystem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index 0cac77e1..373f2b74 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -16,6 +16,7 @@ import json import logging import re +from os.path import realpath from .blockdev import Blockdev, Raiddev, Bcachedev, sort_actions import math @@ -470,6 +471,9 @@ class FilesystemModel(ModelPolicy): if not mountpoint.startswith('/'): raise ValueError('Does not start with /') + # remove redundent // and .. + mountpoint = realpath(mountpoint) + # /usr/include/linux/limits.h:PATH_MAX if len(mountpoint) > 4095: raise ValueError('Path exceeds PATH_MAX')