From b0a4bb2604751254b82717bca040fe8a327980c9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 5 Jul 2021 17:14:32 +0200 Subject: [PATCH] Fix #81223: flock() only locks first byte of file `flock()` should lock the whole file, like on other systems which use mandatory locking. We cannot use `0` like for `flck.l_len`, so we use the largest number, what is valid according to the documentation: . --- ext/standard/flock_compat.c | 2 +- ext/standard/tests/file/bug81223.phpt | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/file/bug81223.phpt diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c index fd9a2e098516e..8bbf6fb895725 100644 --- a/ext/standard/flock_compat.c +++ b/ext/standard/flock_compat.c @@ -116,7 +116,7 @@ PHPAPI int php_flock(int fd, int operation) */ { HANDLE hdl = (HANDLE) _get_osfhandle(fd); - DWORD low = 1, high = 0; + DWORD low = 0xFFFFFFFF, high = 0xFFFFFFFF; OVERLAPPED offset = {0, 0, 0, 0, NULL}; DWORD err; diff --git a/ext/standard/tests/file/bug81223.phpt b/ext/standard/tests/file/bug81223.phpt new file mode 100644 index 0000000000000..0331d631bc8d4 --- /dev/null +++ b/ext/standard/tests/file/bug81223.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #81223 (flock() only locks first byte of file) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) + +Notice: fread(): read of %d bytes failed with errno=13 Permission denied in %s on line %d +bool(false) + +Notice: fread(): read of %d bytes failed with errno=13 Permission denied in %s on line %d +bool(false)