From 793e5a5b2baea560e4802641dab81c9df6eefe66 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 12 Sep 2020 17:38:02 +0200 Subject: [PATCH 1/3] Promote some warnings to ValueError in OCI8 --- ext/oci8/oci8.stub.php | 4 +- ext/oci8/oci8_arginfo.h | 4 +- ext/oci8/oci8_interface.c | 110 +++++++++++++++++--------------------- 3 files changed, 54 insertions(+), 64 deletions(-) diff --git a/ext/oci8/oci8.stub.php b/ext/oci8/oci8.stub.php index 8e8537274a58a..a0a07532e3b36 100644 --- a/ext/oci8/oci8.stub.php +++ b/ext/oci8/oci8.stub.php @@ -412,14 +412,14 @@ function oci_get_implicit_resultset($statement_resource) {} /** * @param resource $statement_resource */ -function oci_set_prefetch($statement_resource, int $number_of_rows): ?bool {} +function oci_set_prefetch($statement_resource, int $number_of_rows): bool {} /** * @param resource $statement_resource * @alias oci_set_prefetch * @deprecated */ -function ocisetprefetch($statement_resource, int $number_of_rows): ?bool {} +function ocisetprefetch($statement_resource, int $number_of_rows): bool {} /** * @param resource $connection_resource diff --git a/ext/oci8/oci8_arginfo.h b/ext/oci8/oci8_arginfo.h index 32852789996dc..3e66fc3fc2e43 100644 --- a/ext/oci8/oci8_arginfo.h +++ b/ext/oci8/oci8_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 2d553815c21edd58bc29b1ca8d294d5750fd7312 */ + * Stub hash: b795b3009f220d578fc93134bd9f07dd685b6493 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0) ZEND_ARG_INFO(0, statement_resource) @@ -292,7 +292,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_get_implicit_resultset, 0, 0, 1) ZEND_ARG_INFO(0, statement_resource) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 0) ZEND_ARG_INFO(0, statement_resource) ZEND_ARG_TYPE_INFO(0, number_of_rows, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 26f8dfdc401bf..334c9d6d80d2c 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -109,8 +109,8 @@ PHP_FUNCTION(oci_define_by_name) ZEND_PARSE_PARAMETERS_END(); if (!name_len) { - php_error_docref(NULL, E_WARNING, "Column name cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); } PHP_OCI_ZVAL_TO_STATEMENT(stmt, statement); @@ -210,8 +210,8 @@ PHP_FUNCTION(oci_bind_array_by_name) } if (max_array_len <= 0) { - php_error_docref(NULL, E_WARNING, "Maximum array length must be greater than zero"); - RETURN_FALSE; + zend_argument_value_error(4, "must be greater than 0"); + RETURN_THROWS(); } if (php_oci_bind_array_by_name(statement, name, (sb4) name_len, bind_var, max_array_len, max_item_len, type)) { @@ -257,6 +257,11 @@ PHP_FUNCTION(oci_lob_save) RETURN_THROWS(); } + if (offset < 0) { + zend_argument_value_error(3, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) { php_error_docref(NULL, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; @@ -264,11 +269,6 @@ PHP_FUNCTION(oci_lob_save) PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor); - if (offset < 0) { - php_error_docref(NULL, E_WARNING, "Offset parameter must be greater than or equal to 0"); - RETURN_FALSE; - } - if (php_oci_lob_write(descriptor, (ub4) offset, data, (ub4) data_len, &bytes_written)) { RETURN_FALSE; } @@ -284,7 +284,7 @@ PHP_FUNCTION(oci_lob_import) char *filename; size_t filename_len; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) { RETURN_THROWS(); } @@ -293,11 +293,6 @@ PHP_FUNCTION(oci_lob_import) RETURN_FALSE; } - if (CHECK_NULL_PATH(filename, filename_len)) { - php_error_docref(NULL, E_WARNING, "filename must not contain null bytes"); - RETURN_FALSE; - } - PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor); if (php_oci_lob_import(descriptor, filename)) { @@ -354,6 +349,11 @@ PHP_FUNCTION(oci_lob_read) RETURN_THROWS(); } + if (length <= 0) { + zend_argument_value_error(2, "must be greater than 0"); + RETURN_THROWS(); + } + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) { php_error_docref(NULL, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; @@ -361,11 +361,6 @@ PHP_FUNCTION(oci_lob_read) PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor); - if (length <= 0) { - php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); - RETURN_FALSE; - } - if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len)) { RETURN_FALSE; } @@ -604,13 +599,13 @@ PHP_FUNCTION(oci_lob_truncate) RETURN_THROWS(); } - if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) { - php_error_docref(NULL, E_WARNING, "Unable to find descriptor property"); - RETURN_FALSE; + if (trim_length < 0) { + zend_argument_value_error(2, "must be greater than or equal to zero"); + RETURN_THROWS(); } - if (trim_length < 0) { - php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero"); + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) { + php_error_docref(NULL, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } @@ -640,15 +635,15 @@ PHP_FUNCTION(oci_lob_erase) if (offset_is_null) { offset = -1; } else if (offset < 0) { - php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } if (length_is_null) { length = -1; } else if (length < 0) { - php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0"); - RETURN_FALSE; + zend_argument_value_error(3, "must be greater than or equal to 0"); + RETURN_THROWS(); } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) { @@ -756,6 +751,13 @@ PHP_FUNCTION(oci_lob_copy) RETURN_THROWS(); } + if (length_is_null) { + length = -1; + } else if (length < 0) { + zend_argument_value_error(3, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor")-1)) == NULL) { php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object"); RETURN_FALSE; @@ -769,13 +771,6 @@ PHP_FUNCTION(oci_lob_copy) PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_dest, descriptor_dest); PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_from, descriptor_from); - if (length_is_null) { - length = -1; - } else if (length < 0) { - php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); - RETURN_FALSE; - } - if (php_oci_lob_copy(descriptor_dest, descriptor_from, length)) { RETURN_FALSE; } @@ -831,22 +826,22 @@ PHP_FUNCTION(oci_lob_export) php_stream *stream; ub4 lob_length; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) { RETURN_THROWS(); } if (start_is_null) { start = -1; } else if (start < 0) { - php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0"); - RETURN_FALSE; + zend_argument_value_error(3, "must be greater than or equal to 0"); + RETURN_THROWS(); } if (length_is_null) { length = -1; } else if (length < 0) { - php_error_docref(NULL, E_WARNING, "length parameter must be greater than or equal to 0"); - RETURN_FALSE; + zend_argument_value_error(4, "must be greater than or equal to 0"); + RETURN_THROWS(); } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) { @@ -854,11 +849,6 @@ PHP_FUNCTION(oci_lob_export) RETURN_FALSE; } - if (CHECK_NULL_PATH(filename, filename_len)) { - php_error_docref(NULL, E_WARNING, "filename must not contain null bytes"); - RETURN_FALSE; - } - PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor); if (php_oci_lob_get_length(descriptor, &lob_length)) { @@ -1630,8 +1620,8 @@ PHP_FUNCTION(oci_set_prefetch) PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement); if (size < 0) { - php_error_docref(NULL, E_WARNING, "Number of rows to be prefetched has to be greater than or equal to 0"); - return; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } if (php_oci_statement_set_prefetch(statement, (ub4)size)) { @@ -1899,16 +1889,16 @@ PHP_FUNCTION(oci_password_change) PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); if (!user_len) { - php_error_docref(NULL, E_WARNING, "Username cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); } if (!pass_old_len) { - php_error_docref(NULL, E_WARNING, "Old password cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(3, "cannot be empty"); + RETURN_THROWS(); } if (!pass_new_len) { - php_error_docref(NULL, E_WARNING, "New password cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(4, "cannot be empty"); + RETURN_THROWS(); } if (php_oci_password_change(connection, user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len)) { @@ -1918,16 +1908,16 @@ PHP_FUNCTION(oci_password_change) } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "ssss", &dbname, &dbname_len, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) { if (!user_len) { - php_error_docref(NULL, E_WARNING, "Username cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); } if (!pass_old_len) { - php_error_docref(NULL, E_WARNING, "Old password cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(3, "cannot be empty"); + RETURN_THROWS(); } if (!pass_new_len) { - php_error_docref(NULL, E_WARNING, "New password cannot be empty"); - RETURN_FALSE; + zend_argument_value_error(4, "cannot be empty"); + RETURN_THROWS(); } connection = php_oci_do_connect_ex(user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len, dbname, (int) dbname_len, NULL, OCI_DEFAULT, 0, 0); From af842a9788e11c4ddca7dc3b8bb1e253debda4d9 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Mon, 14 Sep 2020 17:12:29 +1000 Subject: [PATCH 2/3] Tweaks and test updates for PR 6116 --- ext/oci8/oci8.stub.php | 8 ++--- ext/oci8/oci8_arginfo.h | 6 ++-- ext/oci8/oci8_interface.c | 14 ++++---- ext/oci8/tests/array_bind_002.phpt | 8 +++-- ext/oci8/tests/define1.phpt | 10 +++--- ext/oci8/tests/lob_003.phpt | Bin 1652 -> 1689 bytes ext/oci8/tests/lob_020.phpt | Bin 2845 -> 3454 bytes ext/oci8/tests/lob_022.phpt | 10 ++++-- ext/oci8/tests/lob_027.phpt | 21 +++++++----- ext/oci8/tests/lob_035.phpt | 35 ++++++++++++++----- ext/oci8/tests/lob_042.phpt | 11 +++--- ext/oci8/tests/null_byte_1.phpt | 23 +++++++------ ext/oci8/tests/refcur_prefetch_1.phpt | 47 +++++++++++--------------- 13 files changed, 112 insertions(+), 81 deletions(-) diff --git a/ext/oci8/oci8.stub.php b/ext/oci8/oci8.stub.php index a0a07532e3b36..917225f562655 100644 --- a/ext/oci8/oci8.stub.php +++ b/ext/oci8/oci8.stub.php @@ -87,13 +87,13 @@ function oci_lob_copy(OCILob $lob_descriptor_to, OCILob $lob_descriptor_from, ?i function oci_lob_is_equal(OCILob $lob_descriptor_first, OCILob $lob_descriptor_second): bool {} -function oci_lob_export(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {} +function oci_lob_export(OCILob $lob_descriptor, string $filename, ?int $start = null, ?int $length = null): bool {} /** * @alias oci_lob_export * @deprecated */ -function ociwritelobtofile(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {} +function ociwritelobtofile(OCILob $lob_descriptor, string $filename, ?int $start = null, ?int $length = null): bool {} /** * @param resource $connection_resource @@ -718,13 +718,13 @@ public function getbuffering() {} * @alias oci_lob_export * @return bool */ - public function writetofile(string $path, ?int $start = null, ?int $length = null) {} + public function writetofile(string $filename, ?int $start = null, ?int $length = null) {} /** * @alias oci_lob_export * @return bool */ - public function export(string $path, ?int $start = null, ?int $length = null) {} + public function export(string $filename, ?int $start = null, ?int $length = null) {} /** * @alias oci_lob_write_temporary diff --git a/ext/oci8/oci8_arginfo.h b/ext/oci8/oci8_arginfo.h index 3e66fc3fc2e43..0bcc18f06a1fc 100644 --- a/ext/oci8/oci8_arginfo.h +++ b/ext/oci8/oci8_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b795b3009f220d578fc93134bd9f07dd685b6493 */ + * Stub hash: 6cdc7c967ce80c39eaef1c860ba8f8aa2cb3c979 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0) ZEND_ARG_INFO(0, statement_resource) @@ -124,7 +124,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_export, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, lob_descriptor, OCILob, 0) - ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() @@ -498,7 +498,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_OCILob_getbuffering arginfo_class_OCILob_load ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_writetofile, 0, 0, 1) - ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 334c9d6d80d2c..0f817e36510d2 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -258,7 +258,7 @@ PHP_FUNCTION(oci_lob_save) } if (offset < 0) { - zend_argument_value_error(3, "must be greater than or equal to 0"); + zend_argument_value_error(2, "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -350,7 +350,7 @@ PHP_FUNCTION(oci_lob_read) } if (length <= 0) { - zend_argument_value_error(2, "must be greater than 0"); + zend_argument_value_error(1, "must be greater than 0"); RETURN_THROWS(); } @@ -600,7 +600,7 @@ PHP_FUNCTION(oci_lob_truncate) } if (trim_length < 0) { - zend_argument_value_error(2, "must be greater than or equal to zero"); + zend_argument_value_error(1, "must be greater than or equal to zero"); RETURN_THROWS(); } @@ -635,14 +635,14 @@ PHP_FUNCTION(oci_lob_erase) if (offset_is_null) { offset = -1; } else if (offset < 0) { - zend_argument_value_error(2, "must be greater than or equal to 0"); + zend_argument_value_error(1, "must be greater than or equal to 0"); RETURN_THROWS(); } if (length_is_null) { length = -1; } else if (length < 0) { - zend_argument_value_error(3, "must be greater than or equal to 0"); + zend_argument_value_error(2, "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -833,14 +833,14 @@ PHP_FUNCTION(oci_lob_export) if (start_is_null) { start = -1; } else if (start < 0) { - zend_argument_value_error(3, "must be greater than or equal to 0"); + zend_argument_value_error(2, "must be greater than or equal to 0"); RETURN_THROWS(); } if (length_is_null) { length = -1; } else if (length < 0) { - zend_argument_value_error(4, "must be greater than or equal to 0"); + zend_argument_value_error(3, "must be greater than or equal to 0"); RETURN_THROWS(); } diff --git a/ext/oci8/tests/array_bind_002.phpt b/ext/oci8/tests/array_bind_002.phpt index 14635356ba6a3..863f543c0f5a4 100644 --- a/ext/oci8/tests/array_bind_002.phpt +++ b/ext/oci8/tests/array_bind_002.phpt @@ -50,7 +50,11 @@ $statement = oci_parse($c, "BEGIN array_bind_002_pkg.iobind(:c1); END;"); $array = Array("06-DEC-05","10-DEC-80","21-AUG-91","26-OCT-17","05-NOV-05"); -oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT); +try { + oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} oci_execute($statement); @@ -59,7 +63,7 @@ var_dump($array); echo "Done\n"; ?> --EXPECTF-- -Warning: oci_bind_array_by_name(): Maximum array length must be greater than zero in %s on line %d +oci_bind_array_by_name(): Argument #4 ($maximum_array_length) must be greater than 0 Warning: oci_execute(): ORA-%r(01008|57000)%r: %s in %s on line %d array(5) { diff --git a/ext/oci8/tests/define1.phpt b/ext/oci8/tests/define1.phpt index 73178ae622748..e79fd76e1b9bd 100644 --- a/ext/oci8/tests/define1.phpt +++ b/ext/oci8/tests/define1.phpt @@ -26,7 +26,11 @@ $stmt = oci_parse($c, "select string from define1_tab"); $string = ''; var_dump(oci_define_by_name($stmt, "STRING", $string, 20)); var_dump(oci_define_by_name($stmt, "STRING", $string, 20)); -var_dump(oci_define_by_name($stmt, "", $string, 20)); +try { + var_dump(oci_define_by_name($stmt, "", $string, 20)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} oci_execute($stmt); @@ -48,8 +52,6 @@ echo "Done\n"; --EXPECTF-- bool(true) bool(false) - -Warning: oci_define_by_name(): Column name cannot be empty in %s on line %d -bool(false) +oci_define_by_name(): Argument #2 ($column_name) cannot be empty string(4) "some" Done diff --git a/ext/oci8/tests/lob_003.phpt b/ext/oci8/tests/lob_003.phpt index 80bead5964bd291cbe7f9d8bb66d433ddb58daf4..e06d15109c15d2eb67f04c3815b2d103346b608f 100644 GIT binary patch delta 157 zcmeyuGn01%FAG;mQKdpPmjVz>=4Fw!sZ~f$EJ@B#&QG<6h|V)B%%xoRi#ut;onWLe8-W|Rg{{TqM>P} z;8>Jinwy$eqM&T3prMkJnwMUZp{bBtT3n)#l&X*pR92E&q)?KPn5SSc*@sO705c3P A9smFU delta 119 zcmbQq`-Nu%FU#aY7V*h?ENq(#S&lHqafK%qgOCZ=d;S}FLX z=B1ZpC=?_XCFZ73aTkw TN%{FX8fl3+#i^Q;3)wUPClMzj diff --git a/ext/oci8/tests/lob_020.phpt b/ext/oci8/tests/lob_020.phpt index affdef912634d259fff24e1f081288bad00c5ff5..241b2c7c30f282bd079fa8dc97914d805f016e75 100644 GIT binary patch literal 3454 zcmcIn|4-sb6u+PQSG;s+0f(akXB^v0@PRE^#-_&<@bOGSi(I{bN@h z8BOSvR52B(CS+tvt2Vgjm{D)TsV`@pL2v^uon~qgYDw4IB-;!6gWgs9>bDKLmTpC; zW`m3l0GfB976JR%vK*-}@F`^q!_?)^h`^FNQRN|gOtE9c^L<9=VN7Ktl1y=-1-s|% z@FGN1prqC?OjsNa7bbqU)L*d+yLJVP!irxvXFr7+QpI8VH;rb9y+`N37zi%U2Aw`i zS$9N)@obu*ZJpUX2%)R=i+C7#Ol~iG-OsQIL6_Yg46ZNE`T_dn=;Dr???1~lhWrM$-#@X9MBVM3`HjZMkF_S?#f6k(j=7MSYR0$% znGxh~L6{_wN;s3NWzzV>;)i+d^E-?H_+RPL)VGR~gC}k;QL@H764B2F%ZHbkf0Mc$ zzQlvKfzFX}0UJ8i3}`NV**UP}TWeDCXfXgh>gKWF*=n!O8RCL7YHa31LGb4_609Ck z`0zUtuZxYOgB|1DP7H26CxKhLbjkj9(n72XD)~%A)ZK|a;3H6rjDm}}If7EwLw-n@ zat{wZ^Ts=G0)@;XYGfd2j(X> z-EyUdOW1$cJxJf1TCifkzjG(wnqFrA@~LkeRv5DJ__k<74Z;1EhuP#kK7 z#>O^{4b+%YHdd1tXx!hX@l`&)f0WZz-t%6TQb7m*hdo&W#< delta 275 zcmew-HCJpyGt1-+tdcC6n$}!EhS+3pRuHYo$Tc~IO<{65hwLPFb|9s|qHAQJIk|*G zfm_$mKnKJD>ew8^5x_LricNJg6OX(?cw$jrW?s6Lg1@t;Pkxe>RccXUajJ$UP#`U> xIJIQ*0v_eb>$vbK^hwQ2FUcT6A*zX!<$0wh>$4evoB?99VM?>18jW35JODVQQmg;~ diff --git a/ext/oci8/tests/lob_022.phpt b/ext/oci8/tests/lob_022.phpt index dba5adcbe36cd..3f57122818492 100644 --- a/ext/oci8/tests/lob_022.phpt +++ b/ext/oci8/tests/lob_022.phpt @@ -34,11 +34,15 @@ $clob = oci_new_descriptor($c, OCI_D_LOB); oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB); oci_execute($statement, OCI_DEFAULT); $clob->save("long data"); -$clob->save("long data", -1); $clob->save("long data", 0); -oci_commit($c); +try { + $clob->save("long data", -1); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +oci_commit($c); $query = 'SELECT * FROM lob_test ORDER BY mykey ASC'; $statement = oci_parse ($c, $query); @@ -67,7 +71,7 @@ echo "Done\n"; ?> --EXPECTF-- -Warning: OCILob::save(): Offset parameter must be greater than or equal to 0 in %s on line %d +OCILob::save(): Argument #2 ($offset) must be greater than or equal to 0 string(4) "data" string(9) "long data" string(9) "long data" diff --git a/ext/oci8/tests/lob_027.phpt b/ext/oci8/tests/lob_027.phpt index 05390d1403df0..c21c8a3b43647 100644 --- a/ext/oci8/tests/lob_027.phpt +++ b/ext/oci8/tests/lob_027.phpt @@ -45,7 +45,11 @@ for ($i = 5; $i >= 0; $i--) { $row = oci_fetch_array($s); var_dump($row['BLOB']->load()); - var_dump($row['BLOB']->truncate(($i-1)*10)); + try { + var_dump($row['BLOB']->truncate(($i-1)*10)); + } catch (ValueError $e) { + echo $e->getMessage(), "\n"; + } oci_commit($c); } @@ -56,9 +60,14 @@ oci_execute($s, OCI_DEFAULT); $row = oci_fetch_array($s); var_dump($row['BLOB']->load()); -var_dump($row['BLOB']->truncate(-1)); var_dump($row['BLOB']->truncate(0)); +try { + var_dump($row['BLOB']->truncate(-1)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + oci_commit($c); require __DIR__.'/drop_table.inc'; @@ -95,12 +104,8 @@ bool(true) string(10) "this is a " bool(true) string(0) "" - -Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d -bool(false) +OCILob::truncate(): Argument #1 ($length) must be greater than or equal to zero string(0) "" - -Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d -bool(false) bool(true) +OCILob::truncate(): Argument #1 ($length) must be greater than or equal to zero Done diff --git a/ext/oci8/tests/lob_035.phpt b/ext/oci8/tests/lob_035.phpt index c2240849c249b..53146e1286575 100644 --- a/ext/oci8/tests/lob_035.phpt +++ b/ext/oci8/tests/lob_035.phpt @@ -23,6 +23,7 @@ $blob = oci_new_descriptor($c,OCI_D_LOB); oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB); oci_execute($statement, OCI_DEFAULT); +echo "Writing blob\n"; var_dump($blob->write("some string here. string, I said")); oci_commit($c); @@ -54,21 +55,34 @@ $row2 = oci_fetch_array($s); $dummy = oci_new_descriptor($c, OCI_D_LOB); +//-------------------------------------------------- + +echo "\noci_lob_copy invalid args\n"; + var_dump(oci_lob_copy($dummy, $row1[0])); var_dump(oci_lob_copy($row2[0], $dummy)); - var_dump(oci_lob_copy($row2[0], $row1[0], 0)); -var_dump(oci_lob_copy($row2[0], $row1[0], -1)); var_dump(oci_lob_copy($row2[0], $row1[0], 100000)); +try { + var_dump(oci_lob_copy($row2[0], $row1[0], -1)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + +//-------------------------------------------------- + +echo "\noci_lob_size tests\n"; + var_dump(oci_lob_size($row2[0])); unset($dummy->descriptor); var_dump(oci_lob_size($dummy)); oci_rollback($c); -oci_rollback($c); -oci_commit($c); -oci_commit($c); + +//-------------------------------------------------- + +echo "\nQuery test\n"; $select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE"; $s = oci_parse($c, $select_sql); @@ -82,22 +96,27 @@ echo "Done\n"; ?> --EXPECTF-- +Writing blob int(32) +oci_lob_copy invalid args + Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d bool(false) Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d bool(false) bool(false) - -Warning: oci_lob_copy(): Length parameter must be greater than 0 in %s on line %d -bool(false) bool(true) +oci_lob_copy(): Argument #3 ($length) must be greater than or equal to 0 + +oci_lob_size tests int(0) Warning: oci_lob_size(): Unable to find descriptor property in %s on line %d bool(false) + +Query test array(2) { [0]=> string(0) "" diff --git a/ext/oci8/tests/lob_042.phpt b/ext/oci8/tests/lob_042.phpt index eb447f22afd80..e04c0a0fd7e43 100644 --- a/ext/oci8/tests/lob_042.phpt +++ b/ext/oci8/tests/lob_042.phpt @@ -32,12 +32,17 @@ var_dump($blob->write($str)); var_dump($blob->truncate(1)); var_dump($blob->truncate(1)); var_dump($blob->truncate(2)); -var_dump($blob->truncate(-1)); var_dump($blob->read(2)); var_dump($blob->import("does_not_exist")); var_dump($blob->saveFile("does_not_exist")); +try { + var_dump($blob->truncate(-1)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + require(__DIR__.'/drop_table.inc'); echo "Done\n"; @@ -58,9 +63,6 @@ bool(true) Warning: OCILob::truncate(): Size must be less than or equal to the current LOB size in %s on line %d bool(false) -Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d -bool(false) - Warning: OCILob::read(): Offset must be less than size of the LOB in %s on line %d bool(false) @@ -69,4 +71,5 @@ bool(false) Warning: OCILob::savefile(): Can't open file %s in %s on line %d bool(false) +OCILob::truncate(): Argument #1 ($length) must be greater than or equal to zero Done diff --git a/ext/oci8/tests/null_byte_1.phpt b/ext/oci8/tests/null_byte_1.phpt index f922c62852d8c..d751335b1e868 100644 --- a/ext/oci8/tests/null_byte_1.phpt +++ b/ext/oci8/tests/null_byte_1.phpt @@ -9,7 +9,6 @@ if (PHP_MAJOR_VERSION < 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4)) ?> --INI-- display_errors = On -error_reporting = E_WARNING --FILE-- savefile("/tmp/abc\0def"); -var_dump($r); +try { + $lob->savefile("/tmp/abc\0def"); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} echo "Test 2: Export\n"; -$r = $lob->export("/tmp/abc\0def"); -var_dump($r); +try { + $lob->export("/tmp/abc\0def"); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} ?> --EXPECTF-- Test 1: Import - -Warning: OCILob::savefile(): filename must not contain null bytes in %s on line %d -bool(false) +OCILob::savefile(): Argument #1 ($filename) must not contain any null bytes Test 2: Export - -Warning: OCILob::export(): filename must not contain null bytes in %s on line %d -bool(false) +OCILob::export(): Argument #1 ($filename) must not contain any null bytes diff --git a/ext/oci8/tests/refcur_prefetch_1.phpt b/ext/oci8/tests/refcur_prefetch_1.phpt index 911a4810633ff..0297401f995dc 100644 --- a/ext/oci8/tests/refcur_prefetch_1.phpt +++ b/ext/oci8/tests/refcur_prefetch_1.phpt @@ -61,7 +61,7 @@ for ($i = 0; $i<=500; $i++) { } // Various values for prefetch -$pref = array(0,1,501,499,250,12345,-12345,-1); +$pref = array(0,1,501,499,250,12345); foreach($pref as $value) { echo"-----------------------------------------------\n"; echo "Test with Prefetch value set to $value \n"; @@ -71,6 +71,21 @@ foreach($pref as $value) { fetch_frm_plsql($c,$cur1); } +// Various invalid values for prefetch +$pref = array(-12345,-1); +foreach($pref as $value) { + try { + echo "-----------------------------------------------\n"; + echo "Test with Prefetch (invalid) value set to $value \n"; + echo "-----------------------------------------------\n"; + $cur1 = oci_new_cursor($c); + fetch_frm_php($c,$cur1,$value); + fetch_frm_plsql($c,$cur1); + } catch(ValueError $e) { + echo $e->getMessage(), "\n"; + } +} + // This function sets the prefetch count to the given $value and fetches one row . @@ -206,33 +221,11 @@ Fetch Row from PL/SQL int(0) NULL ----------------------------------------------- -Test with Prefetch value set to -12345 +Test with Prefetch (invalid) value set to -12345 ----------------------------------------------- - -Warning: oci_set_prefetch(): Number of rows to be prefetched has to be greater than or equal to 0 in %s on line %d -Fetch Row from PHP -array(2) { - [0]=> - string(%d) "0" - [1]=> - string(%d) "test0" -} -Fetch Row from PL/SQL -int(101) -string(%d) "test101" +oci_set_prefetch(): Argument #2 ($number_of_rows) must be greater than or equal to 0 ----------------------------------------------- -Test with Prefetch value set to -1 +Test with Prefetch (invalid) value set to -1 ----------------------------------------------- - -Warning: oci_set_prefetch(): Number of rows to be prefetched has to be greater than or equal to 0 in %s on line %d -Fetch Row from PHP -array(2) { - [0]=> - string(%d) "0" - [1]=> - string(%d) "test0" -} -Fetch Row from PL/SQL -int(101) -string(%d) "test101" +oci_set_prefetch(): Argument #2 ($number_of_rows) must be greater than or equal to 0 Done From 2b6d609f14eabfc2cbdbe1bd84f683ca9cb1f6ca Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Tue, 15 Sep 2020 09:36:30 +1000 Subject: [PATCH 3/3] Correct method vs. function arg number usage in error messages --- ext/oci8/oci8_interface.c | 16 +++++++++------- ext/oci8/tests/lob_027.phpt | 4 ++-- ext/oci8/tests/lob_042.phpt | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 0f817e36510d2..91db3f4815fc3 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -40,6 +40,8 @@ #define OCI_STMT_CALL 10 #endif +#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num)) + /* {{{ Register a callback function for Oracle Transparent Application Failover (TAF) */ PHP_FUNCTION(oci_register_taf_callback) { @@ -258,7 +260,7 @@ PHP_FUNCTION(oci_lob_save) } if (offset < 0) { - zend_argument_value_error(2, "must be greater than or equal to 0"); + zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -350,7 +352,7 @@ PHP_FUNCTION(oci_lob_read) } if (length <= 0) { - zend_argument_value_error(1, "must be greater than 0"); + zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0"); RETURN_THROWS(); } @@ -600,7 +602,7 @@ PHP_FUNCTION(oci_lob_truncate) } if (trim_length < 0) { - zend_argument_value_error(1, "must be greater than or equal to zero"); + zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -635,14 +637,14 @@ PHP_FUNCTION(oci_lob_erase) if (offset_is_null) { offset = -1; } else if (offset < 0) { - zend_argument_value_error(1, "must be greater than or equal to 0"); + zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0"); RETURN_THROWS(); } if (length_is_null) { length = -1; } else if (length < 0) { - zend_argument_value_error(2, "must be greater than or equal to 0"); + zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -833,14 +835,14 @@ PHP_FUNCTION(oci_lob_export) if (start_is_null) { start = -1; } else if (start < 0) { - zend_argument_value_error(2, "must be greater than or equal to 0"); + zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0"); RETURN_THROWS(); } if (length_is_null) { length = -1; } else if (length < 0) { - zend_argument_value_error(3, "must be greater than or equal to 0"); + zend_argument_value_error(ERROR_ARG_POS(4), "must be greater than or equal to 0"); RETURN_THROWS(); } diff --git a/ext/oci8/tests/lob_027.phpt b/ext/oci8/tests/lob_027.phpt index c21c8a3b43647..8f5992a555a3a 100644 --- a/ext/oci8/tests/lob_027.phpt +++ b/ext/oci8/tests/lob_027.phpt @@ -104,8 +104,8 @@ bool(true) string(10) "this is a " bool(true) string(0) "" -OCILob::truncate(): Argument #1 ($length) must be greater than or equal to zero +OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0 string(0) "" bool(true) -OCILob::truncate(): Argument #1 ($length) must be greater than or equal to zero +OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0 Done diff --git a/ext/oci8/tests/lob_042.phpt b/ext/oci8/tests/lob_042.phpt index e04c0a0fd7e43..f9e072e0fe68e 100644 --- a/ext/oci8/tests/lob_042.phpt +++ b/ext/oci8/tests/lob_042.phpt @@ -71,5 +71,5 @@ bool(false) Warning: OCILob::savefile(): Can't open file %s in %s on line %d bool(false) -OCILob::truncate(): Argument #1 ($length) must be greater than or equal to zero +OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0 Done