diff options
-rw-r--r-- | package.xml | 5 | ||||
-rw-r--r-- | php_rpminfo.h | 2 | ||||
-rw-r--r-- | rpminfo.c | 44 | ||||
-rw-r--r-- | tests/012-rpmaddtag.phpt | 16 | ||||
-rw-r--r-- | tests/013-rpmdbsearch-error.phpt | 16 |
5 files changed, 80 insertions, 3 deletions
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 </lead> <date>2020-09-23</date> <version> - <release>0.5.2dev</release> + <release>0.6.0dev</release> <api>0.5.0</api> </version> <stability> @@ -26,6 +26,7 @@ Documentation: https://www.php.net/rpminfo <notes> - generate arginfo from stub and add missing default values - raise dependency on PHP 7.2 +- raise exception on bad parameter value with PHP 8 </notes> <contents> <dir name="/"> @@ -56,6 +57,8 @@ Documentation: https://www.php.net/rpminfo <file name="009-rpmdbinfo2.phpt" role="test"/> <file name="010-rpmvercmp_error7.phpt" role="test"/> <file name="011-rpmvercmp_error8.phpt" role="test"/> + <file name="012-rpmaddtag.phpt" role="test"/> + <file name="013-rpmdbsearch-error.phpt" role="test"/> <file name="bidon.rpm" role="test"/> <file name="bidon-src.rpm" role="test"/> </dir> 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) @@ -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<RPMINFO_G(nb_tags) ; i++) { if (RPMINFO_G(tags)[i] == tag) { diff --git a/tests/012-rpmaddtag.phpt b/tests/012-rpmaddtag.phpt new file mode 100644 index 0000000..bf371a4 --- /dev/null +++ b/tests/012-rpmaddtag.phpt @@ -0,0 +1,16 @@ +--TEST-- +Check for rpmaddtag parameter check +--SKIPIF-- +<?php if (!extension_loaded("rpminfo")) print "skip"; ?> +--FILE-- +<?php +var_dump(rpmaddtag(RPMTAG_INSTALLTIME)); +try { + var_dump(rpmaddtag(-1)); +} catch (ValueError $e) { + echo $e->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-- +<?php if (!extension_loaded("rpminfo")) print "skip"; ?> +--FILE-- +<?php +var_dump(rpmdbsearch('notexists', RPMTAG_NAME)); +try { +var_dump(rpmdbsearch('notexists', RPMTAG_NAME, 99)); +} catch (ValueError $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +NULL +%A Unkown rpmmire%A |