From 0b1615d804c778516c8c9ed458b69d7a70aea5bb Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 18 Jun 2021 15:38:04 +0200 Subject: raise exception on bad parameter value with PHP 8 and bump version to 0.6 --- package.xml | 5 ++++- php_rpminfo.h | 2 +- rpminfo.c | 44 +++++++++++++++++++++++++++++++++++++++- tests/012-rpmaddtag.phpt | 16 +++++++++++++++ tests/013-rpmdbsearch-error.phpt | 16 +++++++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 tests/012-rpmaddtag.phpt create mode 100644 tests/013-rpmdbsearch-error.phpt diff --git a/package.xml b/package.xml index 2e88f71..38d8f04 100644 --- a/package.xml +++ b/package.xml @@ -15,7 +15,7 @@ Documentation: https://www.php.net/rpminfo 2020-09-23 - 0.5.2dev + 0.6.0dev 0.5.0 @@ -26,6 +26,7 @@ Documentation: https://www.php.net/rpminfo - generate arginfo from stub and add missing default values - raise dependency on PHP 7.2 +- raise exception on bad parameter value with PHP 8 @@ -56,6 +57,8 @@ Documentation: https://www.php.net/rpminfo + + diff --git a/php_rpminfo.h b/php_rpminfo.h index ec7f126..69ff71e 100644 --- a/php_rpminfo.h +++ b/php_rpminfo.h @@ -22,7 +22,7 @@ extern zend_module_entry rpminfo_module_entry; #define phpext_rpminfo_ptr &rpminfo_module_entry -#define PHP_RPMINFO_VERSION "0.5.2-dev" +#define PHP_RPMINFO_VERSION "0.6.0-dev" #ifdef PHP_WIN32 # define PHP_RPMINFO_API __declspec(dllexport) diff --git a/rpminfo.c b/rpminfo.c index cd6c040..53b9c6c 100644 --- a/rpminfo.c +++ b/rpminfo.c @@ -39,7 +39,7 @@ #endif #ifndef RETURN_THROWS -#define RETURN_THROWS return +#define RETURN_THROWS() return #endif #include "rpminfo_arginfo.h" @@ -375,18 +375,50 @@ PHP_FUNCTION(rpmdbsearch) if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|llb", &name, &len, &crit, &mode, &full) == FAILURE) { RETURN_THROWS(); } + if (rpmTagGetType(crit) == RPM_NULL_TYPE) { +#if PHP_VERSION_ID < 80000 + php_error_docref(NULL, E_WARNING, "Unkown rpmtag"); + RETURN_NULL(); +#else + zend_argument_value_error(2, "Unkown rpmtag"); + RETURN_THROWS(); +#endif + } + if (mode != RPMMIRE_DEFAULT && + mode != RPMMIRE_STRCMP && + mode != RPMMIRE_REGEX && + mode != RPMMIRE_GLOB && + mode != -1) { +#if PHP_VERSION_ID < 80000 + php_error_docref(NULL, E_WARNING, "Unkown rpmmire"); + RETURN_NULL(); +#else + zend_argument_value_error(3, "Unkown rpmmire"); + RETURN_THROWS(); +#endif + } if (crit == RPMTAG_PKGID) { if (len != 32) { +#if PHP_VERSION_ID < 80000 php_error_docref(NULL, E_WARNING, "Bad length for PKGID, 32 expected"); RETURN_NULL(); +#else + zend_argument_value_error(1, "Bad length for PKGID, 32 expected"); + RETURN_THROWS(); +#endif } len = hex2bin(name, MD5, len); name = MD5; } else if (crit == RPMTAG_HDRID) { if (len != 40) { +#if PHP_VERSION_ID < 80000 php_error_docref(NULL, E_WARNING, "Bad length for HDRID, 40 expected"); RETURN_NULL(); +#else + zend_argument_value_error(1, "Bad length for HDRID, 40 expected"); + RETURN_THROWS(); +#endif } } else if (crit == RPMTAG_INSTALLTID) { tid = atol(name); @@ -510,6 +542,16 @@ PHP_FUNCTION(rpmaddtag) RETURN_THROWS(); } + if (rpmTagGetType(tag) == RPM_NULL_TYPE) { +#if PHP_VERSION_ID < 80000 + php_error_docref(NULL, E_WARNING, "Unkown rpmtag"); + RETURN_BOOL(0); +#else + zend_argument_value_error(1, "Unkown rpmtag"); + RETURN_THROWS(); +#endif + } + if (RPMINFO_G(tags)) { for (i=0 ; i +--FILE-- +getMessage(); +} +?> +--EXPECTF-- +bool(true) +%A Unkown rpmtag%A diff --git a/tests/013-rpmdbsearch-error.phpt b/tests/013-rpmdbsearch-error.phpt new file mode 100644 index 0000000..4a61227 --- /dev/null +++ b/tests/013-rpmdbsearch-error.phpt @@ -0,0 +1,16 @@ +--TEST-- +Check for rpmdbinfo function +--SKIPIF-- + +--FILE-- +getMessage(); +} +?> +--EXPECTF-- +NULL +%A Unkown rpmmire%A -- cgit