From fba2f32c5320d97b107e6e7201c22abed7e7a44a Mon Sep 17 00:00:00 2001 From: decaseal Date: Mon, 2 Apr 2018 18:38:43 +0300 Subject: [PATCH] table function file - fix path validate [#add_table_function_file] --- dbms/src/TableFunctions/TableFunctionFile.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dbms/src/TableFunctions/TableFunctionFile.cpp b/dbms/src/TableFunctions/TableFunctionFile.cpp index 06a9210bb60..39039211167 100644 --- a/dbms/src/TableFunctions/TableFunctionFile.cpp +++ b/dbms/src/TableFunctions/TableFunctionFile.cpp @@ -46,11 +46,16 @@ namespace DB std::string structure = static_cast(*args[2]).value.safeGet(); /// Validate path - std::string clickhouse_path = Poco::Path(context.getPath()).makeAbsolute().toString(); - std::string absolute_path = Poco::Path(path).absolute().toString(); + Poco::Path clickhouse_data_poco_path = Poco::Path(context.getPath() + '/data').makeAbsolute(); + std::string clickhouse_data_path = clickhouse_data_poco_path.toString(); - if (!startsWith(absolute_path, clickhouse_path)) - throw Exception("Part path " + absolute_path + " is not inside " + clickhouse_path, ErrorCodes::LOGICAL_ERROR); + Poco::Path poco_path = Poco::Path(path); + if (poco_path.isRelative()) + poco_path = Poco::Path(clickhouse_data_poco_path, poco_path); + std::string absolute_path = poco_path.absolute().toString(); + + if (!startsWith(absolute_path, clickhouse_data_path)) + throw Exception("Part path " + absolute_path + " is not inside " + clickhouse_data_path, ErrorCodes::LOGICAL_ERROR); // Create sample block std::vector structure_vals;