Skip to content

Conversation

@lanodan
Copy link
Contributor

@lanodan lanodan commented Jan 29, 2025

Fix TOCTOU, meaning :file.make_dir returning {:error, :eexists} is
now tested without having to trigger a race-condition.
Also change dir?() returning false from returning :eexist to :enotdir

And handling errors from parent directory creation allows to avoid
non-sensical errors like File.mkdir_p returning :enoent instead of :eacces

@josevalim
Copy link
Member

Thank you for the PR, can you please expand which errors/issues are you trying to avoid?

@lanodan
Copy link
Contributor Author

lanodan commented Jan 30, 2025

For TOCTOU, the first dir?() is effectively useless and hid false status from the second dir?() not being handled correctly as it would return {:error, :eexists} instead of the more proper {:error, :enotdir}, which happens when parallel calls to mkdir_p are done with shared parent directories which needs to be created.

And one problem which Pleroma has been hitting few times is one of the parent directories having wrong permissions,
currently Elixir just ignores the error and so ends up with "No such file or directory" errors (which makes no sense for mkdir_p) instead of "Permission denied".

@lanodan lanodan force-pushed the toctou-mkdir_p branch 2 times, most recently from 563c823 to b336838 Compare January 30, 2025 05:05
@josevalim
Copy link
Member

And one problem which Pleroma has been hitting few times is one of the parent directories having wrong permissions,
currently Elixir just ignores the error and so ends up with "No such file or directory" errors (which makes no sense for mkdir_p) instead of "Permission denied".

Fantastic, can we please try to add a test that reproduces this then? Thank you!

Fix TOCTOU, meaning :file.make_dir returning {:error, :eexists} is
now tested without having to trigger a race-condition.
Also change dir?() returning false from returning :eexist to :enotdir

And handling errors from parent directory creation allows to avoid
non-sensical errors like File.mkdir_p returning :enoent instead of :eacces
@josevalim josevalim merged commit 07afa71 into elixir-lang:main Jan 30, 2025
7 of 9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

github-actions bot pushed a commit to kphrx/pleroma that referenced this pull request Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants