Subject: | share-mode locking bug |
Date: | Wed, 25 Nov 2020 20:00:51 -0500 |
To: | bug-File-NFSLock [...] rt.cpan.org |
From: | Steven Lim <stevenslim [...] gmail.com> |
Hi. This could be characterized as misuse of the module, but I think
there's a shared locking bug
in NFSLock-1.29.
Given the following:
- two processes of different user
- each process attempts to acquire a common lock file in shared mode
The first process will successfully acquire the share mode lock. If a
second process of a different user attempts to acquire the same lock,
NFSLock will return success even though it has failed to append the lock
file with the host and pid info.
NFSLock::do_lock_shared calls create_magic ($self->{lock_file}) when the
link fails (expected if the lock already exists). In create_magic, an
undef is returned if the lock file can't be opened - as would happen if the
lock file belongs to a different user. Although create_magic returns an
undef, do_lock_shared doesn't check status from create_magic (the real bug
here). This means do_lock_shared will return success even if the lock file
was never appended with the new lock owner's info.
Although this could be considered misuse, I think it would be simple enough
to check the status from create_magic and fail the locking operation in
do_lock_shared.
Thanks
Steven