Skip to content

PDO Unconditional errors #6212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 50 commits into from
Closed

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Sep 25, 2020

A couple of unrelated refactoring changes that I made should be able to land on their own if it makes the PR too noisy.

Used only PDO MySQL for tests so hopefully not too many more drivers complain.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please apply the bug fix separately (together with corresponding test changes)?

@nikic
Copy link
Member

nikic commented Sep 25, 2020

And please also apply at least "Inverse logic in do_fetch() to reduce a level of indentation" separately, as the indentation changes makes it hard to understand the diff.

@Girgias Girgias force-pushed the pdo-unconditional-error branch from 19bc7ab to 1f276da Compare September 25, 2020 13:48
@Girgias Girgias mentioned this pull request Sep 25, 2020
@Girgias Girgias force-pushed the pdo-unconditional-error branch 5 times, most recently from ebdc73b to 9d79ad6 Compare September 26, 2020 17:50
@Girgias Girgias force-pushed the pdo-unconditional-error branch from b03e59e to 32b0b47 Compare September 27, 2020 22:37
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass ... this is huge

@Girgias
Copy link
Member Author

Girgias commented Sep 28, 2020

Pushing review changed before the ZPP variadic revert which I'm doing now

@Girgias Girgias force-pushed the pdo-unconditional-error branch from 5e67d6d to 0ae6ecb Compare September 28, 2020 12:05
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good

@@ -1963,6 +2009,8 @@ PHP_METHOD(PDOStatement, debugDumpParams)
ZEND_PARSE_PARAMETERS_NONE();

PHP_STMT_GET_OBJ;

/* TODO: Change to assertion? */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confident it can't fail, e.g. >&- is used.

@@ -62,6 +63,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa
param->name = zend_string_init(name, strlen(name), 0);
return 1;
}
/* TODO Error? */
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this happens if you use an out of bounds parameter number? I think generally it would make sense for things like this to throw, but we need to be careful that native & emulated prepared statements have the same behavior. I don't know whether both go through this codepath.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those trigger if the param name/number is not present. I would imagine they both go through this code path as this is something internal to PDO which is not exposed, as all PDO bind param/value methods go through this. Or do emulated prepared statements somehow override the PDO methods?

Indentation
Error message
Use variadic number position for pdo_stmt_setup_fetch_mode() param cehcks
Use values from *args directly instead of preassigning them in pdo_stmt_setup_fetch_mode()
Drop todo comment
@Girgias Girgias force-pushed the pdo-unconditional-error branch from 0ae6ecb to e4a13d0 Compare September 28, 2020 13:43
Indent (again)
Drop unnecessary cehck
Improve title + SKIPIF for PDO SQLite test
);
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given",
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be of type ?array, %s given",

"ctor_args must be an array"
);
PDO_HANDLE_DBH_ERR();
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given",
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be of type ?array, %s given",

/* Figure out correct class */
if (arg2) {
if (Z_TYPE_P(arg2) != IS_STRING) {
zend_argument_type_error(2, "must be string, %s given", zend_zval_type_name(arg2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(2, "must be string, %s given", zend_zval_type_name(arg2));
zend_argument_type_error(2, "must be of type string, %s given", zend_zval_type_name(arg2));

if (arg2) {
// Reuse convert_to_long(arg2); ?
if (Z_TYPE_P(arg2) != IS_LONG) {
zend_argument_type_error(2, "must be int, %s given", zend_zval_type_name(arg2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(2, "must be int, %s given", zend_zval_type_name(arg2));
zend_argument_type_error(2, "must be of type int, %s given", zend_zval_type_name(arg2));

return false;
}
if (Z_TYPE(args[0]) != IS_LONG) {
zend_argument_type_error(arg1_arg_num, "must be int, %s given", zend_zval_type_name(&args[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(arg1_arg_num, "must be int, %s given", zend_zval_type_name(&args[0]));
zend_argument_type_error(arg1_arg_num, "must be of type int, %s given", zend_zval_type_name(&args[0]));

return false;
}
if (Z_TYPE(args[0]) != IS_STRING) {
zend_argument_type_error(arg1_arg_num, "must be string, %s given", zend_zval_type_name(&args[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(arg1_arg_num, "must be string, %s given", zend_zval_type_name(&args[0]));
zend_argument_type_error(arg1_arg_num, "must be of type string, %s given", zend_zval_type_name(&args[0]));

retval = FAILURE;
} else if (Z_TYPE(args[1]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL(args[1]))) {
ZVAL_ARR(&stmt->fetch.cls.ctor_args, zend_array_dup(Z_ARRVAL(args[1])));
zend_argument_type_error(constructor_arg_num, "must be ?array, %s given",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(constructor_arg_num, "must be ?array, %s given",
zend_argument_type_error(constructor_arg_num, "must be of type ?array, %s given",

if (SUCCESS == retval) {
ZVAL_COPY(&stmt->fetch.into, &args[0]);
if (Z_TYPE(args[0]) != IS_OBJECT) {
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0]));
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0]));
Suggested change
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0]));
zend_argument_type_error(arg1_arg_num, "must be of type object, %s given", zend_zval_type_name(&args[0]));

@@ -1857,18 +1891,27 @@ PHP_METHOD(PDOStatement, setFetchMode)
zval *args = NULL;
uint32_t num_args = 0;

/* Support null for constructor arguments for BC */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment now a bit out of place

#define PDO_LONG_PARAM_CHECK \
if (Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_STRING && Z_TYPE_P(value) != IS_FALSE && Z_TYPE_P(value) != IS_TRUE) { \
pdo_raise_impl_error(dbh, NULL, "HY000", "attribute value must be an integer"); \
PDO_HANDLE_DBH_ERR(); \
zend_type_error("Attribute value must be int for selected attribute, %s given", zend_zval_type_name(value)); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_type_error("Attribute value must be int for selected attribute, %s given", zend_zval_type_name(value)); \
zend_type_error("Attribute value must be of type int for selected attribute, %s given", zend_zval_type_name(value)); \

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG assuming CI happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants