Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Nov 25, 2024
2 parents d3a6757 + 9f4d0e4 commit 8c8ab06
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

name:
- mac-x64
Expand Down
31 changes: 21 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,39 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v0.4.16](https://github.com/NoiseByNorthwest/php-spx/compare/0.4.15...0.4.16)
## [v0.4.17](https://github.com/NoiseByNorthwest/php-spx/compare/v0.4.16...v0.4.17)

### Added
- PHP 8.4 support [#270](https://github.com/NoiseByNorthwest/php-spx/pull/270)
- Subnet mask support for IP matching [#261](https://github.com/NoiseByNorthwest/php-spx/pull/261)
- ZTS PHP beta support [#260](https://github.com/NoiseByNorthwest/php-spx/pull/260)

### Fixed
- Keep scroll position in flatprofile view on repaint [#267](https://github.com/NoiseByNorthwest/php-spx/pull/267)
- Improved confinement check for file access from WEB UI [#255](https://github.com/NoiseByNorthwest/php-spx/pull/255)

## [v0.4.16](https://github.com/NoiseByNorthwest/php-spx/compare/v0.4.15...v0.4.16)

### Added
- Local snapshots of jQuery & jscolor in order to remove the internet access dependency of the Web UI [#217](https://github.com/NoiseByNorthwest/php-spx/issues/217)

### Fixed
- Fixed unconfined server file access from WEB UI [#251](https://github.com/NoiseByNorthwest/php-spx/issues/251)

## [v0.4.15](https://github.com/NoiseByNorthwest/php-spx/compare/0.4.14...0.4.15)
## [v0.4.15](https://github.com/NoiseByNorthwest/php-spx/compare/v0.4.14...v0.4.15)

### Added
- Added Debian builds to github workflow [#222](https://github.com/NoiseByNorthwest/php-spx/pull/222)
- Added PHP8.3 support [#230](https://github.com/NoiseByNorthwest/php-spx/pull/230)
- Added PHP5.4 support [#227](https://github.com/NoiseByNorthwest/php-spx/pull/227)
- Added PHP 8.3 support [#230](https://github.com/NoiseByNorthwest/php-spx/pull/230)
- Added PHP 5.4 support [#227](https://github.com/NoiseByNorthwest/php-spx/pull/227)

### Fixed
- Fixed ESM module imports in Web UI [#233](https://github.com/NoiseByNorthwest/php-spx/issues/233)
- Fixed zlib.h path resolution for macOS/Macport [#238](https://github.com/NoiseByNorthwest/php-spx/issues/238)
- Fixed non-portable path expectation in tests [#221](https://github.com/NoiseByNorthwest/php-spx/pull/221)


## [v0.4.14](https://github.com/NoiseByNorthwest/php-spx/compare/0.4.13...0.4.14)
## [v0.4.14](https://github.com/NoiseByNorthwest/php-spx/compare/v0.4.13...v0.4.14)

### Added
- Added simple search feature
Expand All @@ -36,7 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed buffer overflow in str_builder


## [v0.4.13](https://github.com/NoiseByNorthwest/php-spx/compare/0.4.12...0.4.13)
## [v0.4.13](https://github.com/NoiseByNorthwest/php-spx/compare/v0.4.12...v0.4.13)

### Added
- Github Actions workflow ([#180](https://github.com/NoiseByNorthwest/php-spx/issues/180))
Expand All @@ -50,7 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Travis CI [#195](https://github.com/NoiseByNorthwest/php-spx/issues/195)


## [v0.4.0](https://github.com/NoiseByNorthwest/php-spx/compare/0.3.0...0.4.0)
## [v0.4.0](https://github.com/NoiseByNorthwest/php-spx/compare/v0.3.0...v0.4.0)

### Added
- Analysis screen: fix the NaNs in time grid when time goes above 1000s (fixes [#65](https://github.com/NoiseByNorthwest/php-spx/issues/65))
Expand All @@ -66,7 +77,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix build on macOS 10.11- (fixes [#78](https://github.com/NoiseByNorthwest/php-spx/pull/78))


## [v0.3.0](https://github.com/NoiseByNorthwest/php-spx/compare/0.2.0...0.3.0)
## [v0.3.0](https://github.com/NoiseByNorthwest/php-spx/compare/v0.2.0...v0.3.0)

### Added
- Improve documentation around web UI requirements (fixes [#54](https://github.com/NoiseByNorthwest/php-spx/issues/54))
Expand All @@ -93,7 +104,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Web UI / analysis screen: improved layout


## [v0.2.0](https://github.com/NoiseByNorthwest/php-spx/compare/0.1.2...0.2.0)
## [v0.2.0](https://github.com/NoiseByNorthwest/php-spx/compare/v0.1.2...v0.2.0)

### Added
- Add web UI ([#14](https://github.com/NoiseByNorthwest/php-spx/pull/14))
Expand All @@ -106,7 +117,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Remove Callgrind report type ([#11](https://github.com/NoiseByNorthwest/php-spx/issues/11))


## [v0.1.2](https://github.com/NoiseByNorthwest/php-spx/compare/0.1.2...0.1.2)
## [v0.1.2](https://github.com/NoiseByNorthwest/php-spx/compare/v0.1.2...v0.1.2)

### Added
- Add macOS support ([orls](https://github.com/orls) in [#13](https://github.com/NoiseByNorthwest/php-spx/pull/13))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See the [LICENSE][:link-license:] file for more information.
[:badge-ci:]: https://github.com/NoiseByNorthwest/php-spx/actions/workflows/main.yml/badge.svg
[:link-ci:]: https://github.com/NoiseByNorthwest/php-spx/actions/workflows/main.yml

[:badge-php-versions:]: https://img.shields.io/badge/php-5.4--8.3-blue.svg
[:badge-php-versions:]: https://img.shields.io/badge/php-5.4--8.4-blue.svg
[:badge-supported-platforms:]: https://img.shields.io/badge/platform-GNU/Linux%20|%20macOS%20|%20FreeBSD%20-yellow
[:badge-supported-arch:]: https://img.shields.io/badge/architecture-x86--64%20|%20ARM64%20-silver

Expand Down
10 changes: 3 additions & 7 deletions assets/web-ui/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,21 +573,17 @@ class Widget {

this.repaintTimeout = setTimeout(
() => {
let initialScrollPos = 0;
this.repaintTimeout = null;

const id = this.container.attr('id');
// Remember the scroll position
let scroll = 0;
if (id === 'flatprofile') {
scroll = $(`#flatprofile div`).scrollTop();
initialScrollPos = document.querySelector('#flatprofile > div').scrollTop;
}
this.clear();
this.render();
// Restore the scroll position
if (id === 'flatprofile') {
$(`#flatprofile div`).scrollTop(scroll);
} else {
$(`#${id}`).scrollTop(scroll);
document.querySelector('#flatprofile > div').scrollTop = initialScrollPos;
}
},
0
Expand Down
6 changes: 6 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ if test "$PHP_SPX" = "yes"; then
CFLAGS="$CFLAGS -DCONTINUOUS_INTEGRATION"
fi

if test "$(uname -s 2>/dev/null)" = "Darwin"
then
# see discussion here https://github.com/NoiseByNorthwest/php-spx/pull/270
CFLAGS="$CFLAGS -Wno-typedef-redefinition"
fi

if test "$PHP_SPX_DEV" = "yes"
then
CFLAGS="$CFLAGS -g"
Expand Down
9 changes: 2 additions & 7 deletions src/php_spx.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static int check_access(void)
int found = 0;

SPX_UTILS_TOKENIZE_STRING(SPX_G(http_trusted_proxies), ',', trusted_proxy_ip_str, 64, {
if (0 == strcmp(proxy_ip_str, trusted_proxy_ip_str)) {
if (spx_utils_ip_match(proxy_ip_str, trusted_proxy_ip_str)) {
found = 1;
}
});
Expand Down Expand Up @@ -586,18 +586,13 @@ static int check_access(void)
}

SPX_UTILS_TOKENIZE_STRING(authorized_ips_str, ',', authorized_ip_str, 64, {
if (0 == strcmp(ip_str, authorized_ip_str)) {
if (spx_utils_ip_match(ip_str, authorized_ip_str)) {
/* ip authorized (OK, as well as all previous checks) -> granted */

return 1;
}
});

if (0 == strcmp(authorized_ips_str, "*")) {
/* all ips authorized */
return 1;
}

spx_php_log_notice(
"access not granted: \"%s\" IP is not in white list (\"%s\")",
ip_str,
Expand Down
6 changes: 3 additions & 3 deletions src/php_spx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
# error "Only x86-64 and ARM64 architectures are supported"
#endif

#if ZEND_MODULE_API_NO < 20100525 || ZEND_MODULE_API_NO > 20230831 // 8.3-RC5
# error "Only the following PHP versions are supported: 5.4 to 8.3"
#if ZEND_MODULE_API_NO < 20100525 || ZEND_MODULE_API_NO > 20240924
# error "Only the following PHP versions are supported: 5.4 to 8.4"
#endif

#if defined(ZTS) && !defined(CONTINUOUS_INTEGRATION)
# error "ZTS is not yet supported"
#endif

#define PHP_SPX_EXTNAME "SPX"
#define PHP_SPX_VERSION "0.4.15"
#define PHP_SPX_VERSION "0.4.17"

extern zend_module_entry spx_module_entry;
86 changes: 46 additions & 40 deletions src/spx_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ typedef void (*execute_internal_func_t) (
);

static struct {
#if ZEND_MODULE_API_NO >= 20151012
void * (*malloc) (size_t size);
void (*free) (void * ptr);
void * (*realloc) (void * ptr, size_t size);
size_t (*block_size) (void * ptr);
#endif

#if ZEND_MODULE_API_NO < 20121212
void (*execute) (zend_op_array * op_array TSRMLS_DC);
#else
Expand Down Expand Up @@ -124,9 +117,6 @@ static struct {
#endif
);
} ze_hooked_func = {
#if ZEND_MODULE_API_NO >= 20151012
NULL, NULL, NULL, NULL,
#endif
NULL, NULL, NULL,
NULL, NULL,
#if ZEND_MODULE_API_NO >= 20151012
Expand All @@ -135,6 +125,17 @@ static struct {
NULL
};

#if ZEND_MODULE_API_NO >= 20151012
static SPX_THREAD_TLS struct {
void * (*malloc) (size_t size);
void (*free) (void * ptr);
void * (*realloc) (void * ptr, size_t size);
size_t (*block_size) (void * ptr);
} ze_tls_hooked_func = {
NULL, NULL, NULL, NULL
};
#endif

static SPX_THREAD_TLS struct {
struct {
struct {
Expand Down Expand Up @@ -664,24 +665,28 @@ void spx_php_execution_init(void)
#if ZEND_MODULE_API_NO >= 20151012
zend_mm_heap * ze_mm_heap = zend_mm_get_heap();

/*
* FIXME document why we need ze_mm_custom_block_size instead of ze_mm_block_size
* when there is no previous MM custom handler.
*/
ze_tls_hooked_func.block_size = ze_mm_custom_block_size;

zend_mm_get_custom_handlers(
ze_mm_heap,
&ze_hooked_func.malloc,
&ze_hooked_func.free,
&ze_hooked_func.realloc
&ze_tls_hooked_func.malloc,
&ze_tls_hooked_func.free,
&ze_tls_hooked_func.realloc
);

ze_hooked_func.block_size = ze_mm_custom_block_size;

if (
!ze_hooked_func.malloc
|| !ze_hooked_func.free
|| !ze_hooked_func.realloc
!ze_tls_hooked_func.malloc
|| !ze_tls_hooked_func.free
|| !ze_tls_hooked_func.realloc
) {
ze_hooked_func.malloc = ze_mm_malloc;
ze_hooked_func.free = ze_mm_free;
ze_hooked_func.realloc = ze_mm_realloc;
ze_hooked_func.block_size = ze_mm_block_size;
ze_tls_hooked_func.malloc = ze_mm_malloc;
ze_tls_hooked_func.free = ze_mm_free;
ze_tls_hooked_func.realloc = ze_mm_realloc;
ze_tls_hooked_func.block_size = ze_mm_block_size;
}

zend_mm_set_custom_handlers(
Expand All @@ -697,24 +702,24 @@ void spx_php_execution_shutdown(void)
{
#if ZEND_MODULE_API_NO >= 20151012
if (
ze_hooked_func.malloc
&& ze_hooked_func.free
&& ze_hooked_func.realloc
ze_tls_hooked_func.malloc
&& ze_tls_hooked_func.free
&& ze_tls_hooked_func.realloc
) {
zend_mm_heap * ze_mm_heap = zend_mm_get_heap();

if (
/*
* ze_hooked_func.malloc was defaulted to ze_mm_malloc only if there were no
* ze_tls_hooked_func.malloc was defaulted to ze_mm_malloc only if there were no
* previous custom handlers.
*/
ze_hooked_func.malloc != ze_mm_malloc
ze_tls_hooked_func.malloc != ze_mm_malloc
) {
zend_mm_set_custom_handlers(
ze_mm_heap,
ze_hooked_func.malloc,
ze_hooked_func.free,
ze_hooked_func.realloc
ze_tls_hooked_func.malloc,
ze_tls_hooked_func.free,
ze_tls_hooked_func.realloc
);
} else {
/*
Expand All @@ -733,9 +738,10 @@ void spx_php_execution_shutdown(void)
}
}

ze_hooked_func.malloc = NULL;
ze_hooked_func.free = NULL;
ze_hooked_func.realloc = NULL;
ze_tls_hooked_func.malloc = NULL;
ze_tls_hooked_func.free = NULL;
ze_tls_hooked_func.realloc = NULL;
ze_tls_hooked_func.block_size = NULL;
}
#endif

Expand Down Expand Up @@ -1013,11 +1019,11 @@ static void * ze_mm_realloc(void * ptr, size_t size)

static void * tls_hook_malloc(size_t size)
{
void * ptr = ze_hooked_func.malloc(size);
void * ptr = ze_tls_hooked_func.malloc(size);

if (ptr) {
context.alloc_count++;
context.alloc_bytes += ze_hooked_func.block_size(ptr);
context.alloc_bytes += ze_tls_hooked_func.block_size(ptr);
}

return ptr;
Expand All @@ -1027,17 +1033,17 @@ static void tls_hook_free(void * ptr)
{
if (ptr) {
context.free_count++;
context.free_bytes += ze_hooked_func.block_size(ptr);
context.free_bytes += ze_tls_hooked_func.block_size(ptr);
}

ze_hooked_func.free(ptr);
ze_tls_hooked_func.free(ptr);
}

static void * tls_hook_realloc(void * ptr, size_t size)
{
const size_t old_size = ptr ? ze_hooked_func.block_size(ptr) : 0;
void * new = ze_hooked_func.realloc(ptr, size);
const size_t new_size = new ? ze_hooked_func.block_size(new) : 0;
const size_t old_size = ptr ? ze_tls_hooked_func.block_size(ptr) : 0;
void * new = ze_tls_hooked_func.realloc(ptr, size);
const size_t new_size = new ? ze_tls_hooked_func.block_size(new) : 0;

if (ptr && new) {
if (ptr != new) {
Expand Down
Loading

0 comments on commit 8c8ab06

Please sign in to comment.