Skip to content

ext/pdo: Validate Oracle null handling modes - #24431

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-pdo-attribute-validation-rxt1-84-work
Open

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-pdo-attribute-validation-rxt1-84-work

Conversation

@iliaal

@iliaal iliaal commented Oct 19, 2026

Copy link
Copy Markdown
Member

PDO accepted unsupported values for PDO::ATTR_ORACLE_NULLS and truncated them into its two-bit storage, so 4 silently selected PDO::NULL_NATURAL. Invalid modes now raise ValueError before changing the attribute, including when supplied through constructor options.

Reject unsupported ATTR_ORACLE_NULLS values before narrowing them into the
two-bit field, preserving the previous mode when validation fails. The
constructor and setAttribute() share this validation.
@NattyNarwhal

Copy link
Copy Markdown
Member

I was experimenting with using C23_ENUM for PDO refactoring in a branch I've been working on but haven't submitted yet. If you want, here's an additional patch that also touches on the same enum your PR touches on if you want to add it. It is a bit unfortunate that it's called Oracle nulls rather than something more descriptive.

From b4d1316e21f55e02d4b9e2be557754295428f5e2 Mon Sep 17 00:00:00 2001
From: Calvin Buckley <calvinb@php.net>
Date: Mon, 19 Oct 2026 17:39:49 -0300
Subject: [PATCH 06/10] ext/pdo: convert pdo_null_handling to C23 enum

---
 ext/pdo/php_pdo_driver.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h
index cce888d5b35..1eb5a8794cc 100644
--- a/ext/pdo/php_pdo_driver.h
+++ b/ext/pdo/php_pdo_driver.h
@@ -168,7 +168,7 @@ C23_ENUM(pdo_case_conversion, uint8_t) {
 };
 
 /* oracle interop settings */
-enum pdo_null_handling {
+C23_ENUM(pdo_null_handling, uint8_t) {
 	PDO_NULL_NATURAL = 0,
 	PDO_NULL_EMPTY_STRING = 1,
 	PDO_NULL_TO_STRING = 2
@@ -464,8 +464,8 @@ struct _pdo_dbh_t {
 	/* The PDO Error mode */
 	pdo_error_mode error_mode;
 
-	/* oracle compat; see enum pdo_null_handling */
-	uint8_t oracle_nulls;
+	/* Empty/null string conversion */
+	pdo_null_handling oracle_nulls;
 
 	/* Case conversion */
 	pdo_case_conversion native_case;
-- 
2.54.0

@NattyNarwhal NattyNarwhal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks fine as-is anyways.

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.

2 participants