8000 Avoid target directories within the source directory by Fleuv · Pull Request #29857 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Avoid target directories within the source directory #29857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

Fleuv
Copy link
Contributor
@Fleuv Fleuv commented Jan 11, 2019
Q A
Branch? master
Bug fix? no, but kind of yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

Currently when you run:

$filesystem->mirror('/foo', '/foo/bar');

The method will get caught in a recursive loop of creating "bar" sub directories in the target directory.

This will happen:

/foo/bar/bar/
/foo/bar/bar/bar/
/foo/bar/bar/bar/bar/
...

Until the path is so long that is validated as an invalid path string and thus mkdir() crashes.

In this pull request I implemented an if statement at the beginning of the foreach in the mirror() method. This if statement ensures that the target directory in the mirror process is skipped.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jan 24, 2019
@nicolas-grekas
Copy link
Member

That would qualify as a bug fix to me. Could you please rebase+retarget for 3.4?
Don't forget to fix failures while doing so.
Thanks.

@nicolas-grekas
Copy link
Member

Continued in #30116, thanks @Fleuv

fabpot added a commit that referenced this pull request Mar 31, 2019
…in his child with realpath checks (Fleuv, XuruDragon)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Filesystem] Fix mirroring a directory into itself or in his child with realpath checks

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none / PR #29857
| License       | MIT
| Doc PR        | n/a

This this the continuity of #29857 by @Fleuv

Fix a bug while trying to mirror a directory into itself or in a child
Adding handle real path checks when mirroring.

Commits
-------

8011f49 Handling relative/absolute path
59437a4 Skipping iterations in the mirror() method where the iterated file's path name is equal to the target path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0