From 5b347fe48f647cad3dc5ce1c19b1cdfb2171e798 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 12 Nov 2015 15:37:34 +0100 Subject: [PATCH] Raise error if server received windows path --- gns3server/modules/base_manager.py | 8 ++++++++ tests/modules/test_manager.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 89aea063..253c3f3b 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -23,6 +23,7 @@ import asyncio import aiohttp import socket import shutil +import re import logging log = logging.getLogger(__name__) @@ -401,7 +402,14 @@ class BaseManager: if not path: return "" + img_directory = self.get_images_directory() + + # Windows path should not be send to a unix server + if not sys.platform.startswith("win"): + if re.match(r"^[A-Z]:", path) is not None: + raise VMError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory)) + if not os.path.isabs(path): s = os.path.split(path) path = os.path.normpath(os.path.join(img_directory, *s)) diff --git a/tests/modules/test_manager.py b/tests/modules/test_manager.py index 018d3a9f..adaf4d1d 100644 --- a/tests/modules/test_manager.py +++ b/tests/modules/test_manager.py @@ -117,8 +117,8 @@ def test_get_abs_image_path_non_local(qemu, tmpdir): assert qemu.get_abs_image_path(path1) == path1 with pytest.raises(VMError): qemu.get_abs_image_path(path2) - # with pytest.raises(VMError): - # qemu.get_abs_image_path("C:\\test2.bin") + with pytest.raises(VMError): + qemu.get_abs_image_path("C:\\test2.bin") with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": True}): assert qemu.get_abs_image_path(path2) == path2