diff --git a/src/job/job.cpp b/src/job/job.cpp index c202aad2..92b736fa 100644 --- a/src/job/job.cpp +++ b/src/job/job.cpp @@ -44,7 +44,7 @@ job::~job() void job::check_job_dirs() { // initialize default working directory inside sandbox - working_path_ = fs::path("/box"); + sandbox_working_path_ = fs::path("/box"); if (!fs::exists(temporary_directory_)) { throw job_exception("Working directory not exists"); @@ -135,7 +135,8 @@ void job::build_job() // check relativeness of working directory if (!helpers::check_relative(fs::path(sandbox->working_directory))) { - throw job_exception("Given working directory for task '" + task_meta->task_id + "' is not relative"); + throw job_exception( + "Given working directory for task '" + task_meta->task_id + "' is not relative or contains '..'"); } // go through variables parsing @@ -160,7 +161,7 @@ void job::build_job() logger_, temporary_directory_.string(), source_path_, - working_path_}; + sandbox_working_path_}; task = factory_->create_sandboxed_task(data); @@ -440,7 +441,7 @@ void job::prepare_job_vars() {"JOB_ID", job_meta_->job_id}, {"SOURCE_DIR", source_path_.string()}, {"RESULT_DIR", result_path_.string()}, - {"EVAL_DIR", working_path_.string()}, + {"EVAL_DIR", sandbox_working_path_.string()}, {"TEMP_DIR", fs::temp_directory_path().string()}, {"JUDGES_DIR", fs::path("/usr/bin").string()}}; diff --git a/src/job/job.h b/src/job/job.h index afcded87..ebd9cb1e 100644 --- a/src/job/job.h +++ b/src/job/job.h @@ -141,7 +141,7 @@ class job /** Directory where results and log of job are stored. */ fs::path result_path_; /** Directory inside sandbox which should be bound as the working one. */ - fs::path working_path_; + fs::path sandbox_working_path_; /** Factory for creating tasks. */ std::shared_ptr factory_; /** Progress callback which is called on some important points */ diff --git a/src/tasks/create_params.h b/src/tasks/create_params.h index 099cd752..8271ec69 100644 --- a/src/tasks/create_params.h +++ b/src/tasks/create_params.h @@ -25,7 +25,7 @@ struct create_params { /** directory where source files given by users are located */ fs::path source_path; /** working directory which points inside sandbox */ - fs::path working_path; + fs::path sandbox_working_path; }; diff --git a/src/tasks/external_task.cpp b/src/tasks/external_task.cpp index e94d3400..d207371f 100644 --- a/src/tasks/external_task.cpp +++ b/src/tasks/external_task.cpp @@ -13,7 +13,7 @@ namespace fs = boost::filesystem; external_task::external_task(const create_params &data) : task_base(data.id, data.task_meta), worker_config_(data.worker_conf), sandbox_(nullptr), sandbox_config_(data.task_meta->sandbox), limits_(data.limits), logger_(data.logger), temp_dir_(data.temp_dir), - evaluation_dir_(data.source_path), working_dir_(data.working_path) + evaluation_dir_(data.source_path), sandbox_working_dir_(data.sandbox_working_path) { if (worker_config_ == nullptr) { throw task_exception("No worker configuration provided."); @@ -29,7 +29,7 @@ external_task::external_task(const create_params &data) if (!sandbox_config_->working_directory.empty()) { if (!helpers::check_relative(sandbox_config_->working_directory)) { - throw task_exception("Given working directory in sandbox config is not relative"); + throw task_exception("Given working directory in sandbox config is not relative or contains '..'"); } evaluation_dir_ = fs::path(data.source_path) / sandbox_config_->working_directory; @@ -124,7 +124,7 @@ void external_task::results_output_init() if (sandbox_config_->std_output == "") { remove_stdout_ = true; std::string stdout_file = task_meta_->task_id + "." + random + ".output.stdout"; - sandbox_config_->std_output = (working_dir_ / fs::path(stdout_file)).string(); + sandbox_config_->std_output = (sandbox_working_dir_ / fs::path(stdout_file)).string(); } } @@ -133,7 +133,7 @@ void external_task::results_output_init() if (sandbox_config_->std_error == "") { remove_stderr_ = true; std::string stderr_file = task_meta_->task_id + "." + random + ".output.stderr"; - sandbox_config_->std_error = (working_dir_ / fs::path(stderr_file)).string(); + sandbox_config_->std_error = (sandbox_working_dir_ / fs::path(stderr_file)).string(); } } } diff --git a/src/tasks/external_task.h b/src/tasks/external_task.h index 98aa6015..191b4aab 100644 --- a/src/tasks/external_task.h +++ b/src/tasks/external_task.h @@ -101,7 +101,7 @@ class external_task : public task_base /** Directory outside sandbox where task will be executed */ fs::path evaluation_dir_; /** Directory binded to the sandbox as default working dir */ - fs::path working_dir_; + fs::path sandbox_working_dir_; /** After execution delete stdout file produced by sandbox */ bool remove_stdout_ = false; /** After execution delete stderr file produced by sandbox */