Skip to content

Promote E_NOTICE to Error in PostgreSQL extension #6226

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 4 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Sep 28, 2020

Some of these are obvious type/value errors which is surprising they were classified as E_NOTICE...

And because it is PGSQL none of these conditions are tested :-)

@nikic
Copy link
Member

nikic commented Sep 28, 2020

And because it is PGSQL none of these conditions are tested :-)

We should add some (representative) tests then ^

php_error_docref(NULL, E_NOTICE, "Invalid OID value passed");
RETURN_FALSE;
zend_value_error("Invalid OID value passed");
RETURN_THROWS();
Copy link
Member

Choose a reason for hiding this comment

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

While you're here, indent this block one level?

@@ -2322,25 +2323,26 @@ PHP_FUNCTION(pg_lo_create)
switch (Z_TYPE_P(oid)) {
case IS_STRING:
{
/* TODO: Use zend_is_numeric_string/subroutine? */
Copy link
Member

Choose a reason for hiding this comment

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

No, this code is there to handle integer strings larger than zend_long. is_numeric_string would convert those to floats, which defeats the purpose of this code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, but this code is lot, so maybe make it a dedicated function in the future?

Copy link
Member

Choose a reason for hiding this comment

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

Oh sure, we should extract the common pgsql code (later...)

@@ -2525,6 +2531,7 @@ PHP_FUNCTION(pg_lo_open)
if ((pgsql_lofd = lo_open(pgsql, oid, pgsql_mode)) == -1) {
if (lo_unlink(pgsql, oid) == -1) {
efree(pgsql_lofp);
/* TODO: Throw error? */
Copy link
Member

Choose a reason for hiding this comment

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

Nah, at least going by the message, this is an issue with the environment...

php_error_docref(NULL, E_NOTICE, "Invalid OID value passed");
RETURN_FALSE;
zend_value_error("Invalid OID value passed");
RETURN_THROWS();
Copy link
Member

Choose a reason for hiding this comment

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

Same here, this block is missing an indent.

@@ -5532,7 +5546,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,

ZEND_HASH_FOREACH_STR_KEY_VAL(ht, fld, val) {
if (fld == NULL) {
php_error_docref(NULL, E_NOTICE, "Expects associative array for values to be inserted");
zend_value_error("Array of values must be an associated array of string keys");
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_value_error("Array of values must be an associated array of string keys");
zend_value_error("Array of values must be an associative array with string keys");

@@ -5358,7 +5373,7 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var

ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) {
if (fld == NULL) {
php_error_docref(NULL, E_NOTICE, "Expects associative array for values to be inserted");
zend_value_error("Array of values must be an associative array of string keys");
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_value_error("Array of values must be an associative array of string keys");
zend_value_error("Array of values must be an associative array with string keys");

Also realized this doesn't test the value error code path in build_assignment_string() because the same error condition seems to fail early
@Girgias Girgias force-pushed the pgsql-notice-to-error branch from 46c239e to e327070 Compare September 29, 2020 14:00
@php-pulls php-pulls closed this in 053a5fc Sep 29, 2020
@Girgias Girgias deleted the pgsql-notice-to-error branch September 29, 2020 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants