Skip to content

Conversation

@bduranleau-nr
Copy link
Contributor

No description provided.

@newrelic-php-agent-bot
Copy link

newrelic-php-agent-bot commented Dec 3, 2025

Test Suite Status Result
Multiverse 16/16 passing
SOAK 0/0 passing

#include "nr_datastore_instance.h"

#if ZEND_MODULE_API_NO >= ZEND_8_5_X_API_NO
#define PHP_PDO_DBH zend_object*
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest naming this NR_PHP_PDO_DBH to clarify that it's our define vs a PHP define.

*/
extern pdo_dbh_t* nr_php_pdo_get_database_object(zval* dbh TSRMLS_DC);

/* Purpose : Returns the pdo_dbh_t struct that is contained in the object store
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* Purpose : Returns the pdo_dbh_t struct that is contained in the object store
/*
* Purpose : Returns the pdo_dbh_t struct that is contained in the object store

#else
dbh = &pdo_stmt->database_object_handle;
#endif
dup = nr_php_pdo_duplicate(dbh TSRMLS_CC);
Copy link
Contributor

@zsistla zsistla Dec 4, 2025

Choose a reason for hiding this comment

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

It needs a null check somewhere along the path for dbh.
dbh is passed into nr_php_pdo_duplicate, which for 8.5 passes to nr_php_pdo_get_database_object_from_zend_object which dereferences here.


pdo_dbh_t* nr_php_pdo_get_database_object_from_zend_object(
zend_object* dbh TSRMLS_DC) {
if (nr_php_class_entry_instanceof_class(dbh->ce, "PDO" TSRMLS_CC)) {
Copy link
Contributor

@zsistla zsistla Dec 4, 2025

Choose a reason for hiding this comment

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

NULL check before dereferencing dbh.

}

#if ZEND_MODULE_API_NO >= ZEND_8_5_X_API_NO
return (zval*)nr_hashmap_index_get(NRTXNGLOBAL(pdo_link_options),
Copy link
Contributor

Choose a reason for hiding this comment

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

NULL check before derefencing dbh.

Comment on lines +538 to +542
extern int __attribute__((weak)) php_pdo_parse_data_source(
const char* data_source,
zend_ulong data_source_len,
struct pdo_data_src_parser* parsed,
int nparams);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just formatting?

Comment on lines +124 to +129
static inline pdo_dbh_t*
nr_php_pdo_get_database_object_internal_from_zend_object(
zend_object* dbh TSRMLS_DC) {
return php_pdo_dbh_fetch_inner(dbh);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a NULL check for dbh since php_pdo_dbh_fetch_inner doesn't check.

@zsistla
Copy link
Contributor

zsistla commented Dec 4, 2025

Great solution to address the issue!

Could you please update the description with why the change was needed?

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.

4 participants