Skip to content
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

Implementation of truncate is unsafe #16

Open
s-m-e opened this issue Apr 19, 2019 · 0 comments
Open

Implementation of truncate is unsafe #16

s-m-e opened this issue Apr 19, 2019 · 0 comments

Comments

@s-m-e
Copy link

s-m-e commented Apr 19, 2019

I ran into this issue testing my Python implementation - your C++ implementation shows the same problem:

You implement truncate by calling the truncate system call. As you might have noticed, there is no truncateat system call which would be required for truncating something with a path relative to a file descriptor. So your implementation assumes that its current working directory is never changed throughout its lifetime.

I have spend a while researching it ( 1, 2 ) and it appears that the best solution is to just divert from the truncate system call to an openat-ftruncate-close-sequence. I have successfully tested this with my Python implementation.


EDIT: Actually, this issue applies to most system calls that you use which take a path as an argument. You are always relying on the current working directory. You should use the savefd file descriptor throughout your code and specify paths relative to it.

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

No branches or pull requests

1 participant