com php-src: Fix #78386: fstat mode has unexpected value on PHP 7.4: NEWS ext/standard/tests/file/bug78386.phpt win32/ioutil.c

From: Date: Tue, 20 Aug 2019 14:04:14 +0000
Subject: com php-src: Fix #78386: fstat mode has unexpected value on PHP 7.4: NEWS ext/standard/tests/file/bug78386.phpt win32/ioutil.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-107974@lists.php.net to get a copy of this message
Commit: c03114e55c7b9367fc9be895fe0df01cd1b62cab Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 20 Aug 2019 16:04:14 +0200 Parents: ae923287cada2bb59877e806c8219b74f7d857d5 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c03114e55c7b9367fc9be895fe0df01cd1b62cab Log: Fix #78386: fstat mode has unexpected value on PHP 7.4 We must not assume that any file which is not a directory is a regular file. Therefore we employ GetFileType() in this case to properly distinguish between character special, FIFO special and regular files. Bugs: https://bugs.php.net/78386 Changed paths: M NEWS A ext/standard/tests/file/bug78386.phpt M win32/ioutil.c Diff: diff --git a/NEWS b/NEWS index 013029c..43a4745 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ PHP NEWS . Fixed bug #78406 (Broken file includes with user-defined stream filters). (Nikita) . Fixed bug #72530 (Use After Free in GC with Certain Destructors). (Nikita) + . Fixed bug #78386 (fstat mode has unexpected value on PHP 7.4). (cmb) - Date: . Fixed bug #78383 (Casting a DateTime to array no longer returns its diff --git a/ext/standard/tests/file/bug78386.phpt b/ext/standard/tests/file/bug78386.phpt new file mode 100644 index 0000000..9118761 --- /dev/null +++ b/ext/standard/tests/file/bug78386.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #78386 (fstat mode has unexpected value on PHP 7.4) +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only"); +?> +--FILE-- +<?php +$handle = popen('dir', 'r'); +$stat = fstat($handle); +var_dump(decoct($stat['mode'])); +?> +--EXPECT-- +string(5) "10666" diff --git a/win32/ioutil.c b/win32/ioutil.c index 669876d..f7db410 100644 --- a/win32/ioutil.c +++ b/win32/ioutil.c @@ -942,7 +942,20 @@ static int php_win32_ioutil_fstat_int(HANDLE h, php_win32_ioutil_stat_t *buf, co } if ((data->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0) { - buf->st_mode |= is_dir ? (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)) : S_IFREG; + if (is_dir) { + buf->st_mode |= (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)); + } else { + switch (GetFileType(h)) { + case FILE_TYPE_CHAR: + buf->st_mode |= S_IFCHR; + break; + case FILE_TYPE_PIPE: + buf->st_mode |= S_IFIFO; + break; + default: + buf->st_mode |= S_IFREG; + } + } buf->st_mode |= (data->dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6)); }

« previous php.cvs (#107974) next »