Skip to content

Commit 890f7f4

Browse files
committed
Fix #34957; file access checks should use VCWD_ACCESS()
1 parent 23d3dde commit 890f7f4

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? Oct 2005, PHP 5.1 Release Candidate 4
4+
- Fixed bug #34957 (PHP doesn't respect ACLs for access checks). (Wez)
45
- Fixed fgetcsv() and fputcsv() inconsistency. (Dmitry)
56
- Fixed bug #34934 (offsetExists is not called from array_key_exists). (Dmitry)
67
- Fixed bug #34905 (Digest authentication does not work with Apache 1). (Ilia)

ext/standard/filestat.c

+31-1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ PHP_FUNCTION(clearstatcache)
543543
#define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT)
544544
#define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK)
545545
#define IS_ABLE_CHECK(__t) ((__t) == FS_IS_R || (__t) == FS_IS_W || (__t) == FS_IS_X)
546+
#define IS_ACCESS_CHECK(__t) (IS_ABLE_CHECK(type) || (__t) == FS_EXISTS)
546547

547548
/* {{{ php_stat
548549
*/
@@ -560,6 +561,35 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ
560561
RETURN_FALSE;
561562
}
562563

564+
if (IS_ACCESS_CHECK(type)) {
565+
char *local;
566+
567+
if (php_stream_locate_url_wrapper(filename, &local, 0 TSRMLS_CC) == &php_plain_files_wrapper) {
568+
switch (type) {
569+
#ifdef F_OK
570+
case FS_EXISTS:
571+
RETURN_BOOL(VCWD_ACCESS(local, F_OK) == 0);
572+
break;
573+
#endif
574+
#ifdef W_OK
575+
case FS_IS_W:
576+
RETURN_BOOL(VCWD_ACCESS(local, W_OK) == 0);
577+
break;
578+
#endif
579+
#ifdef R_OK
580+
case FS_IS_R:
581+
RETURN_BOOL(VCWD_ACCESS(local, R_OK) == 0);
582+
break;
583+
#endif
584+
#ifdef X_OK
585+
case FS_IS_X:
586+
RETURN_BOOL(VCWD_ACCESS(local, X_OK) == 0);
587+
break;
588+
#endif
589+
}
590+
}
591+
}
592+
563593
if (IS_LINK_OPERATION(type)) {
564594
flags |= PHP_STREAM_URL_STAT_LINK;
565595
}
@@ -617,7 +647,7 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ
617647
php_stream_wrapper *wrapper;
618648

619649
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC);
620-
if (wrapper && wrapper->wops && wrapper->wops->label && strcmp(wrapper->wops->label, "plainfile") == 0) {
650+
if (wrapper == &php_plain_files_wrapper) {
621651
if (type == FS_IS_X) {
622652
xmask = S_IXROOT;
623653
} else {

main/streams/php_stream_plain_wrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
/* operations for a plain file; use the php_stream_fopen_XXX funcs below */
2424
PHPAPI extern php_stream_ops php_stream_stdio_ops;
25+
PHPAPI extern php_stream_wrapper php_plain_files_wrapper;
2526

2627
BEGIN_EXTERN_C()
2728

0 commit comments

Comments
 (0)