Fix build

This commit is contained in:
kssenii 2021-07-13 22:02:35 +00:00
parent da09ce3f20
commit b393603b57
6 changed files with 9 additions and 11 deletions

View File

@ -130,22 +130,22 @@ bool pathStartsWith(const String & path, const String & prefix_path)
return pathStartsWith(filesystem_path, filesystem_prefix_path);
}
String SQLiteDatabaseValidatePath(const String & path, ContextPtr context)
String SQLiteDatabaseValidatePath(const String & path, const String & user_files_path)
{
auto user_files_path = fs::canonical(context->getUserFilesPath());
String canonical_user_files_path = fs::canonical(user_files_path);
fs::path canonical_path;
String canonical_path;
std::error_code err;
if (fs::path(path).is_relative())
canonical_path = fs::canonical(user_files_path / path, err);
canonical_path = fs::canonical(fs::path(user_files_path) / path, err);
else
canonical_path = fs::canonical(path, err);
if (err)
throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "SQLite database path '{}' is invalid. Error: {}", path, err.message());
if (!canonical_path.string().starts_with(user_files_path.string()))
if (!canonical_path.starts_with(canonical_user_files_path))
throw Exception(ErrorCodes::PATH_ACCESS_DENIED,
"SQLite database file path '{}' must be inside 'user_files' directory", path);

View File

@ -2,7 +2,6 @@
#include <common/types.h>
#include <Common/Exception.h>
#include <Interpreters/Context.h>
#include <filesystem>
#include <memory>
@ -36,7 +35,7 @@ bool pathStartsWith(const std::filesystem::path & path, const std::filesystem::p
/// Returns true if path starts with prefix path
bool pathStartsWith(const String & path, const String & prefix_path);
String SQLiteDatabaseValidatePath(const String & path, ContextPtr context);
String SQLiteDatabaseValidatePath(const String & path, const String & user_files_path);
}
namespace FS

View File

@ -32,7 +32,7 @@ DatabaseSQLite::DatabaseSQLite(
, database_engine_define(database_engine_define_->clone())
, log(&Poco::Logger::get("DatabaseSQLite"))
{
auto db_path = SQLiteDatabaseValidatePath(database_path_, context_);
auto db_path = SQLiteDatabaseValidatePath(database_path_, context_->getUserFilesPath());
sqlite3 * tmp_sqlite_db = nullptr;
int status = sqlite3_open(db_path.c_str(), &tmp_sqlite_db);

View File

@ -159,7 +159,7 @@ void registerStorageSQLite(StorageFactory & factory)
const auto database_path = engine_args[0]->as<ASTLiteral &>().value.safeGet<String>();
const auto table_name = engine_args[1]->as<ASTLiteral &>().value.safeGet<String>();
auto db_path = SQLiteDatabaseValidatePath(database_path, args.getContext());
auto db_path = SQLiteDatabaseValidatePath(database_path, args.getContext()->getUserFilesPath());
sqlite3 * tmp_sqlite_db = nullptr;
int status = sqlite3_open(db_path.c_str(), &tmp_sqlite_db);

View File

@ -76,7 +76,7 @@ void TableFunctionSQLite::parseArguments(const ASTPtr & ast_function, ContextPtr
database_path = args[0]->as<ASTLiteral &>().value.safeGet<String>();
remote_table_name = args[1]->as<ASTLiteral &>().value.safeGet<String>();
auto db_path = SQLiteDatabaseValidatePath(database_path, context);
auto db_path = SQLiteDatabaseValidatePath(database_path, context->getUserFilesPath());
sqlite3 * tmp_sqlite_db = nullptr;
int status = sqlite3_open(db_path.c_str(), &tmp_sqlite_db);

View File

@ -6,7 +6,6 @@ CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# See 01658_read_file_to_string_column.sh
user_files_path=$(clickhouse-client --query "select _path,_file from file('nonexist.txt', 'CSV', 'val1 char')" 2>&1 | grep Exception | awk '{gsub("/nonexist.txt","",$9); print $9}')
user_files_path=/home/kssenii/ClickHouse/programs/server/user_files
mkdir -p ${user_files_path}/
chmod 777 ${user_files_path}