[php-src] master: Fix unchecked sqlite3_column_text() calls (#22715)

Nora Dossche via GitHub <[email protected]> Mon, 20 Jul 2026 16:09:45 +0000
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Nora Dossche (ndossche)
Committer: GitHub (web-flow)
Pusher: ndossche
Date: 2026-07-20T18:09:42+02:00

Commit: https://github.com/php/php-src/commit/b82fc3c0e04b77d88fe6202fdb6f98bb3375e862
Raw diff: https://github.com/php/php-src/commit/b82fc3c0e04b77d88fe6202fdb6f98bb3375e862.diff

Fix unchecked sqlite3_column_text() calls (#22715)

This is the pdo equivalent of GH-22045. Notably it does not include a
change for the blob call because ZVAL_STRINGL_FAST already takes care of
that implicitly.

Changed paths:
  M  ext/pdo_sqlite/sqlite_statement.c


Diff:

diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c
index ca82b1b09322..25c9e6917e43 100644
--- a/ext/pdo_sqlite/sqlite_statement.c
+++ b/ext/pdo_sqlite/sqlite_statement.c
@@ -276,8 +276,13 @@ static int pdo_sqlite_stmt_get_col(
 			int64_t i = sqlite3_column_int64(S->stmt, colno);
 #if SIZEOF_ZEND_LONG < 8
 			if (i > ZEND_LONG_MAX || i < ZEND_LONG_MIN) {
+				const char *text = (const char *) sqlite3_column_text(S->stmt, colno);
+				if (UNEXPECTED(!text)) {
+					pdo_sqlite_error_stmt(stmt);
+					return 0;
+				}
 				ZVAL_STRINGL(result,
-					(char *) sqlite3_column_text(S->stmt, colno),
+					text,
 					sqlite3_column_bytes(S->stmt, colno));
 				return 1;
 			}
@@ -295,10 +300,15 @@ static int pdo_sqlite_stmt_get_col(
 				sqlite3_column_blob(S->stmt, colno), sqlite3_column_bytes(S->stmt, colno));
 			return 1;
 
-		default:
-			ZVAL_STRINGL_FAST(result,
-				(char *) sqlite3_column_text(S->stmt, colno), sqlite3_column_bytes(S->stmt, colno));
+		default: {
+			const char *text = (const char *) sqlite3_column_text(S->stmt, colno);
+			if (UNEXPECTED(!text)) {
+				pdo_sqlite_error_stmt(stmt);
+				return 0;
+			}
+			ZVAL_STRINGL_FAST(result, text, sqlite3_column_bytes(S->stmt, colno));
 			return 1;
+		}
 	}
 }