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

Whole_File doesn't lock the whole file. #6

Open
Rombobeorn opened this issue Oct 2, 2022 · 0 comments
Open

Whole_File doesn't lock the whole file. #6

Rombobeorn opened this issue Oct 2, 2022 · 0 comments

Comments

@Rombobeorn
Copy link

The procedures in POSIX.File_Locking don't properly lock the whole file when Whole_File is True. They look up the file's current size with POSIX.IO.File_Size, and then call fcntl to lock that many bytes. This does not work when another process appends to the file concurrently. Even if the file doesn't grow between the calls to File_Size and fcntl, locking only the file's current size doesn't prevent another process from locking a region past the end and appending to the file.

Quoting the POSIX Programmer's Manual at https://man7.org/linux/man-pages/man3/fcntl.3p.html:

Locks may start and extend beyond the current end of a file, but
shall not extend before the beginning of the file. A lock shall
be set to extend to the largest possible value of the file offset
for that file by setting l_len to 0. If such a lock also has
l_start set to 0 and l_whence is set to SEEK_SET, the whole file
shall be locked.

Replace all three calls to File_Size in posix-file_locking.adb with zero, like this:
Blady-Com/florist@7fdcc75

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