From cedd8e986f4fd475ad02271972c26fd9d1172bbd Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 20 Jan 2022 12:57:37 +0100 Subject: [PATCH 1/9] =?UTF-8?q?gh7875.phpt=20fails=20on=20FreeBSD=20CI=20?= =?UTF-8?q?=E2=80=93=20why=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ext/standard/tests/mail/gh7875.phpt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/standard/tests/mail/gh7875.phpt b/ext/standard/tests/mail/gh7875.phpt index f19fe5f3194f5..ee0daf640241a 100644 --- a/ext/standard/tests/mail/gh7875.phpt +++ b/ext/standard/tests/mail/gh7875.phpt @@ -14,7 +14,10 @@ function exception_error_handler($severity, $message, $file, $line) { set_error_handler("exception_error_handler"); touch(__DIR__ . "/gh7875.mail.log"); -chmod(__DIR__ . "/gh7875.mail.log", 0444); +var_dump(chmod(__DIR__ . "/gh7875.mail.log", 0444)); +var_dump(fileperms(__DIR__ . "/gh7875.mail.log")); +var_dump(file_put_contents(__DIR__ . "/gh7875.mail.log", "foo")); +var_dump(file_get_contents(__DIR__ . "/gh7875.mail.log")); try { mail('recipient@example.com', 'Subject', 'Body', []); From da9a21387cf7c10bbc71beb3f98c5976ff8a9067 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 20 Jan 2022 13:51:16 +0100 Subject: [PATCH 2/9] Add extra test --- tests/what.phpt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/what.phpt diff --git a/tests/what.phpt b/tests/what.phpt new file mode 100644 index 0000000000000..9c12711763d45 --- /dev/null +++ b/tests/what.phpt @@ -0,0 +1,24 @@ +--TEST-- +chmod(0444) makes a file read-only +--FILE-- + +--CLEAN-- + +--EXPECTF-- +bool(true) +bool(true) +string(6) "100444" + +Warning: file_put_contents(%swhat.txt): Failed to open stream: Permission denied in %s on line %d +bool(false) +string(0) "" From 7ad644cfe0377eb44b2d6c0ba4c85802b5347f16 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 20 Jan 2022 14:46:08 +0100 Subject: [PATCH 3/9] statcache issue? --- tests/what.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/what.phpt b/tests/what.phpt index 9c12711763d45..e1d3125530532 100644 --- a/tests/what.phpt +++ b/tests/what.phpt @@ -5,6 +5,7 @@ chmod(0444) makes a file read-only $filename = __DIR__ . "/what.txt"; var_dump(touch($filename)); var_dump(chmod($filename, 0444)); +clearstatcache(); var_dump(decoct(fileperms($filename))); var_dump(file_put_contents($filename, "foo")); var_dump(file_get_contents($filename)); From ecae73deb84ef79f70ad57f17917777a15f08b64 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 20 Jan 2022 16:38:58 +0100 Subject: [PATCH 4/9] debug --- tests/what.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/what.phpt b/tests/what.phpt index e1d3125530532..35a85ac70c304 100644 --- a/tests/what.phpt +++ b/tests/what.phpt @@ -9,6 +9,7 @@ clearstatcache(); var_dump(decoct(fileperms($filename))); var_dump(file_put_contents($filename, "foo")); var_dump(file_get_contents($filename)); +var_dump(file_get_contents("/etc/rc.conf")); ?> --CLEAN-- Date: Thu, 20 Jan 2022 17:13:51 +0100 Subject: [PATCH 5/9] Restore gh7875.phpt --- ext/standard/tests/mail/gh7875.phpt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ext/standard/tests/mail/gh7875.phpt b/ext/standard/tests/mail/gh7875.phpt index ee0daf640241a..f19fe5f3194f5 100644 --- a/ext/standard/tests/mail/gh7875.phpt +++ b/ext/standard/tests/mail/gh7875.phpt @@ -14,10 +14,7 @@ function exception_error_handler($severity, $message, $file, $line) { set_error_handler("exception_error_handler"); touch(__DIR__ . "/gh7875.mail.log"); -var_dump(chmod(__DIR__ . "/gh7875.mail.log", 0444)); -var_dump(fileperms(__DIR__ . "/gh7875.mail.log")); -var_dump(file_put_contents(__DIR__ . "/gh7875.mail.log", "foo")); -var_dump(file_get_contents(__DIR__ . "/gh7875.mail.log")); +chmod(__DIR__ . "/gh7875.mail.log", 0444); try { mail('recipient@example.com', 'Subject', 'Body', []); From 3d64ab19db6f366a17e4f46e548e2095d5c88d3b Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 20 Jan 2022 17:19:58 +0100 Subject: [PATCH 6/9] skip test if file is not read-only --- ext/standard/tests/mail/gh7875.phpt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ext/standard/tests/mail/gh7875.phpt b/ext/standard/tests/mail/gh7875.phpt index f19fe5f3194f5..5043445c57d5e 100644 --- a/ext/standard/tests/mail/gh7875.phpt +++ b/ext/standard/tests/mail/gh7875.phpt @@ -1,5 +1,18 @@ --TEST-- GH-7875 (mails are sent even if failure to log throws exception) +--SKIPIF-- + --INI-- sendmail_path={MAIL:{PWD}/gh7875.mail.out} mail.log={PWD}/gh7875.mail.log From b31757643df75a9cfa8ab5fc6031b5006b0803cc Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 20 Jan 2022 18:43:38 +0100 Subject: [PATCH 7/9] oops --- ext/standard/tests/mail/gh7875.phpt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/standard/tests/mail/gh7875.phpt b/ext/standard/tests/mail/gh7875.phpt index 5043445c57d5e..63e3ae14f0457 100644 --- a/ext/standard/tests/mail/gh7875.phpt +++ b/ext/standard/tests/mail/gh7875.phpt @@ -5,9 +5,7 @@ GH-7875 (mails are sent even if failure to log throws exception) $filename = __DIR__ . "/gh7875.mail.log"; touch($filename); chmod($filename, 0444); -if (@file_put_contents($filename, "foo")) { - unlink($filename); -} +@file_put_contents($filename, "foo"); $contents = file_get_contents($filename); chmod($filename, 0644); unlink($filename); From 6d8e61b9434d4bf6ea641f97f9e3aab96b4d9d78 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 21 Jan 2022 12:20:56 +0100 Subject: [PATCH 8/9] double-check is_writable() --- tests/what.phpt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/what.phpt b/tests/what.phpt index 35a85ac70c304..db76a17b44517 100644 --- a/tests/what.phpt +++ b/tests/what.phpt @@ -7,9 +7,10 @@ var_dump(touch($filename)); var_dump(chmod($filename, 0444)); clearstatcache(); var_dump(decoct(fileperms($filename))); +clearstatcache(); +var_dump(is_writable($filename)); var_dump(file_put_contents($filename, "foo")); var_dump(file_get_contents($filename)); -var_dump(file_get_contents("/etc/rc.conf")); ?> --CLEAN-- Date: Fri, 21 Jan 2022 13:47:48 +0100 Subject: [PATCH 9/9] simplify skipif and remove what.phpt --- ext/standard/tests/mail/gh7875.phpt | 6 +++--- tests/what.phpt | 28 ---------------------------- 2 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 tests/what.phpt diff --git a/ext/standard/tests/mail/gh7875.phpt b/ext/standard/tests/mail/gh7875.phpt index 63e3ae14f0457..0947dcb3538f1 100644 --- a/ext/standard/tests/mail/gh7875.phpt +++ b/ext/standard/tests/mail/gh7875.phpt @@ -5,11 +5,11 @@ GH-7875 (mails are sent even if failure to log throws exception) $filename = __DIR__ . "/gh7875.mail.log"; touch($filename); chmod($filename, 0444); -@file_put_contents($filename, "foo"); -$contents = file_get_contents($filename); +clearstatcache(); +$is_writable = is_writable($filename); chmod($filename, 0644); unlink($filename); -if ($contents === "foo") die("skip cannot make file read-only"); +if ($is_writable) die("skip cannot make file read-only"); ?> --INI-- sendmail_path={MAIL:{PWD}/gh7875.mail.out} diff --git a/tests/what.phpt b/tests/what.phpt deleted file mode 100644 index db76a17b44517..0000000000000 --- a/tests/what.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -chmod(0444) makes a file read-only ---FILE-- - ---CLEAN-- - ---EXPECTF-- -bool(true) -bool(true) -string(6) "100444" -bool(false) - -Warning: file_put_contents(%swhat.txt): Failed to open stream: Permission denied in %s on line %d -bool(false) -string(0) ""