From 2494dcdf42a2f24145a12ec992db20ed134dc5bc Mon Sep 17 00:00:00 2001 From: Go Kudo Date: Mon, 31 Jan 2022 12:09:19 +0900 Subject: [PATCH 1/3] Raise error on invalid serializer. (#1) - Raise error on invalid serializer. Co-authored-by: Go Kudo --- apc_cache.c | 3 +++ tests/serializer_invalid.phpt | 12 ++++++++++++ tests/serializer_valid.phpt | 11 +++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/serializer_invalid.phpt create mode 100644 tests/serializer_valid.phpt diff --git a/apc_cache.c b/apc_cache.c index 480dd001..9b8c01ac 100644 --- a/apc_cache.c +++ b/apc_cache.c @@ -1218,6 +1218,9 @@ PHP_APCU_API zend_bool apc_cache_defense(apc_cache_t *cache, zend_string *key, t PHP_APCU_API void apc_cache_serializer(apc_cache_t* cache, const char* name) { if (cache && !cache->serializer) { cache->serializer = apc_find_serializer(name); + if (strcmp(name, "default") != 0 && !cache->serializer) { + php_error_docref(NULL, E_WARNING, "apc_cache_serializer: serializer \"%s\" is not supported.", name); + } } } /* }}} */ diff --git a/tests/serializer_invalid.phpt b/tests/serializer_invalid.phpt new file mode 100644 index 00000000..b0d83c03 --- /dev/null +++ b/tests/serializer_invalid.phpt @@ -0,0 +1,12 @@ +--TEST-- +Serializer: invalid pattern. +--SKIPIF-- + +--INI-- +apc.enabled=1 +apc.enable_cli=1 +apc.serializer=igbinary +--FILE-- + +--INI-- +apc.enabled=1 +apc.enable_cli=1 +apc.serializer=php +--FILE-- + Date: Tue, 1 Feb 2022 09:53:38 +0900 Subject: [PATCH 2/3] Update apc_cache.c thanks @nikic Co-authored-by: Nikita Popov --- apc_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apc_cache.c b/apc_cache.c index 9b8c01ac..7e7e7a19 100644 --- a/apc_cache.c +++ b/apc_cache.c @@ -1219,7 +1219,7 @@ PHP_APCU_API void apc_cache_serializer(apc_cache_t* cache, const char* name) { if (cache && !cache->serializer) { cache->serializer = apc_find_serializer(name); if (strcmp(name, "default") != 0 && !cache->serializer) { - php_error_docref(NULL, E_WARNING, "apc_cache_serializer: serializer \"%s\" is not supported.", name); + php_error_docref(NULL, E_WARNING, "apc_cache_serializer: serializer \"%s\" is not supported", name); } } } /* }}} */ From ba858a4ce6ceaa2622b74e89e3871950ff232916 Mon Sep 17 00:00:00 2001 From: Go Kudo Date: Tue, 1 Feb 2022 11:53:14 +0900 Subject: [PATCH 3/3] fix test --- tests/serializer_invalid.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/serializer_invalid.phpt b/tests/serializer_invalid.phpt index b0d83c03..bd4c662e 100644 --- a/tests/serializer_invalid.phpt +++ b/tests/serializer_invalid.phpt @@ -9,4 +9,4 @@ apc.serializer=igbinary --FILE--