From 520c00a5bffd87a5318c487bf1b778a53e8298d4 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: . Closes GH-7216. --- NEWS | 3 +++ ext/standard/flock_compat.c | 2 +- ext/standard/tests/file/bug81223.phpt | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/file/bug81223.phpt diff --git a/NEWS b/NEWS index 0001bdf6892..527d999a051 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,9 @@ PHP NEWS - PCRE: . Fixed bug #81101 (PCRE2 10.37 shows unexpected result). (Anatol) +- Standard: + . Fixed bug #81223 (flock() only locks first byte of file). (cmb) + 01 Jul 2021, PHP 7.4.21 - Core: diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c index fd9a2e09851..8bbf6fb8957 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 00000000000..0331d631bc8 --- /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)