diff --git a/NEWS b/NEWS index e26c9eca2fdb..b19b09c21442 100644 --- a/NEWS +++ b/NEWS @@ -78,6 +78,9 @@ PHP NEWS . Mark Phar::buildFromIterator() base directory argument as a path. (ndossche) +- Posix: + . Added validity check to the flags argument for posix_access(). (arshidkv12) + - Reflection: . Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true for classes with property hooks). (alexandre-daubois) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 77a06370cc73..7af90f665854 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1410,10 +1410,7 @@ PHP_FUNCTION(mysqli_stmt_send_long_data) RETURN_THROWS(); } - if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)) { - RETURN_FALSE; - } - RETURN_TRUE; + RETURN_BOOL(!mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)); } /* }}} */ @@ -1552,10 +1549,7 @@ PHP_FUNCTION(mysqli_stmt_reset) MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID); - if (mysql_stmt_reset(stmt->stmt)) { - RETURN_FALSE; - } - RETURN_TRUE; + RETURN_BOOL(!mysql_stmt_reset(stmt->stmt)); } /* }}} */ diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index a3a796628bbc..4b5d9d577c5d 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -3023,10 +3023,7 @@ PHP_FUNCTION(pg_lo_export) pgsql = link->conn; - if (lo_export(pgsql, oid, ZSTR_VAL(file_out)) == -1) { - RETURN_FALSE; - } - RETURN_TRUE; + RETURN_BOOL(lo_export(pgsql, oid, ZSTR_VAL(file_out)) != -1); } /* }}} */ @@ -3863,10 +3860,8 @@ PHP_FUNCTION(pg_connection_reset) pgsql = link->conn; PQreset(pgsql); - if (PQstatus(pgsql) == CONNECTION_BAD) { - RETURN_FALSE; - } - RETURN_TRUE; + + RETURN_BOOL(PQstatus(pgsql) != CONNECTION_BAD); } /* }}} */ diff --git a/ext/posix/posix.c b/ext/posix/posix.c index b7acf8c75127..76e14f6ecb0c 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -744,6 +744,15 @@ PHP_FUNCTION(posix_access) RETURN_FALSE; } + if (mode < 0 || (mode & ~(F_OK | R_OK | W_OK | X_OK))) { + zend_argument_value_error( + 2, + "must be a bitmask of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK" + ); + efree(path); + RETURN_THROWS(); + } + ret = access(path, mode); efree(path); diff --git a/ext/posix/tests/posix_access_flags.phpt b/ext/posix/tests/posix_access_flags.phpt new file mode 100644 index 000000000000..0989e2a2bc66 --- /dev/null +++ b/ext/posix/tests/posix_access_flags.phpt @@ -0,0 +1,54 @@ +--TEST-- +posix_access() flag (mode) validation +--SKIPIF-- + +--FILE-- +getMessage(), "\n"; +} + +try { + posix_access($testfile, 01000); // S_ISVTX bit (sticky) +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + +try { + posix_access($testfile, 02000); // S_ISGID bit +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + +if (posix_access($testfile, POSIX_R_OK | POSIX_W_OK)) { + echo "Read/write access OK\n"; +} + +if (posix_access($testfile, POSIX_F_OK)) { + echo "File exists OK\n"; +} + +?> +--CLEAN-- + +--EXPECTF-- +posix_access(): Argument #2 ($flags) must be a bitmask of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK +posix_access(): Argument #2 ($flags) must be a bitmask of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK +posix_access(): Argument #2 ($flags) must be a bitmask of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK +Read/write access OK +File exists OK diff --git a/ext/standard/dns_win32.c b/ext/standard/dns_win32.c index 1f7c6c0146e4..8caf5813395c 100644 --- a/ext/standard/dns_win32.c +++ b/ext/standard/dns_win32.c @@ -116,11 +116,7 @@ PHP_FUNCTION(dns_check_record) status = DnsQuery_A(hostname, type, DNS_QUERY_STANDARD, NULL, &pResult, NULL); - if (status) { - RETURN_FALSE; - } - - RETURN_TRUE; + RETURN_BOOL(!status); } /* }}} */ diff --git a/ext/standard/file.c b/ext/standard/file.c index bd6ee252875e..a7b73f1fe56e 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1016,10 +1016,8 @@ PHPAPI PHP_FUNCTION(fflush) ZEND_PARSE_PARAMETERS_END(); ret = php_stream_flush(stream); - if (ret) { - RETURN_FALSE; - } - RETURN_TRUE; + + RETURN_BOOL(!ret); } /* }}} */ @@ -1032,10 +1030,7 @@ PHPAPI PHP_FUNCTION(rewind) PHP_Z_PARAM_STREAM(stream) ZEND_PARSE_PARAMETERS_END(); - if (-1 == php_stream_rewind(stream)) { - RETURN_FALSE; - } - RETURN_TRUE; + RETURN_BOOL(-1 != php_stream_rewind(stream)); } /* }}} */ diff --git a/win32/signal.c b/win32/signal.c index 49a7c1cc0c91..89548a2405c4 100644 --- a/win32/signal.c +++ b/win32/signal.c @@ -131,10 +131,7 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler) if (!ZEND_FCI_INITIALIZED(fci)) { zval_ptr_dtor(&ctrl_handler); ZVAL_UNDEF(&ctrl_handler); - if (!SetConsoleCtrlHandler(NULL, add)) { - RETURN_FALSE; - } - RETURN_TRUE; + RETURN_BOOL(SetConsoleCtrlHandler(NULL, add)); } if (!SetConsoleCtrlHandler(NULL, FALSE) || !SetConsoleCtrlHandler(php_win32_signal_system_ctrl_handler, add)) {