Protect mountpoint from relative paths and duplicate pathsep

Use os.path.realpath() to clean up any path manipulations

Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
This commit is contained in:
Ryan Harper 2015-11-19 13:55:58 -06:00
parent 0d850d7a6d
commit 35c5a0b279
1 changed files with 4 additions and 0 deletions

View File

@ -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')