From: Varsha Rao Date: Thu, 16 Jul 2020 10:50:36 +0000 (+0530) Subject: mgr/nfs: Check if pseudo path is absolute path or just '/' X-Git-Tag: v16.1.0~1636^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a6f8470f51a1df1e5863d4c26c925bf39df4ef55;p=ceph.git mgr/nfs: Check if pseudo path is absolute path or just '/' Fixes: https://tracker.ceph.com/issues/46565 Signed-off-by: Varsha Rao --- diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index 279d73e30ed1..a08646d33655 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -3,6 +3,7 @@ import json import logging from typing import List import socket +from os.path import isabs, normpath from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec from rados import TimedOut @@ -514,9 +515,9 @@ class FSExport(object): def format_path(self, path): if path: - path = path.strip() - if len(path) > 1 and path[-1] == '/': - path = path[:-1] + path = normpath(path.strip()) + if path[:2] == "//": + path = path[1:] return path def check_fs(self, fs_name): @@ -529,6 +530,11 @@ class FSExport(object): if not self.check_fs(fs_name): return -errno.ENOENT, "", f"filesystem {fs_name} not found" + pseudo_path = self.format_path(pseudo_path) + if not isabs(pseudo_path) or pseudo_path == "/": + return -errno.EINVAL, "", f"pseudo path {pseudo_path} is invalid. "\ + "It should not be absolute path or just '/'." + if cluster_id not in self.exports: self.exports[cluster_id] = [] @@ -541,7 +547,7 @@ class FSExport(object): access_type = "RO" ex_dict = { 'path': self.format_path(path), - 'pseudo': self.format_path(pseudo_path), + 'pseudo': pseudo_path, 'cluster_id': cluster_id, 'access_type': access_type, 'fsal': {"name": "CEPH", "user_id": user_id,