Skip to content

Conversation

@kangpinghuang
Copy link
Contributor

There is a bug to use symbolic link directory as storage root path.
It is a problem that whether the path is canonical

There is a bug to use symbolic link directory as storage root path.
It is a problem that whether the path is canonical
DCHECK_EQ(_download_type, ERROR_LOG);
if (FileSystemUtil::contain_path(_error_log_root_dir, file_path)) {
std::string canonical_file_path = canonical(file_path).string();
if (FileSystemUtil::contain_path(canonical(_error_log_root_dir).string(), canonical_file_path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_error_log_root_dir should be set after canonical when initializing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just call canonical in DownloadAction construct method?

std::string canonical_file_path = canonical(file_path).string();
for (auto& allow_path : _allow_paths) {
if (FileSystemUtil::contain_path(allow_path, file_path)) {
if (FileSystemUtil::contain_path(canonical(allow_path).string(), canonical_file_path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with _error_log_root_dir to _allow_paths

@imay
Copy link
Contributor

imay commented Nov 22, 2018

@kangpinghuang
And you need to change your commit log to describe what you fixed


Status DownloadAction::check_log_path_is_allowed(const std::string& file_path) {
DCHECK_EQ(_download_type, ERROR_LOG);
if (FileSystemUtil::contain_path(_error_log_root_dir, file_path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to get canonical path in a unified place?
Or you may miss somewhere.

In DownloadAction, checking fails by comparing canonical path with noncanonical path.
So fix the bug by convert all path to canonical path before comparison

_download_type(NORMAL) {
for (auto& dir : allow_dirs) {
_allow_paths.emplace_back(std::move(canonical(dir).string()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canonical(dir).string() is already a rvalue, you needn't to call std::move

@kangpinghuang kangpinghuang changed the title Fix bug of #307 Fix bug of using symbolic link dir as storage path Nov 22, 2018
@morningman
Copy link
Contributor

ISSUE #307

Copy link
Contributor

@imay imay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morningman morningman merged commit be6e9c3 into apache:master Nov 23, 2018
@kangpinghuang kangpinghuang deleted the fix_307 branch August 13, 2019 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants