Raise error if server received windows path

pull/370/head
Julien Duponchelle 9 years ago
parent 58e7fa2f01
commit 5b347fe48f

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

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

Loading…
Cancel
Save