Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 May 2021 11:44:25 GMT
From:      Torsten Zuehlsdorff <tz@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 8aea544d5b4c - main - databases/php74-pdo_pgsql: Apply patch for PHP Bug 81002
Message-ID:  <202105051144.145BiPtl097342@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by tz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8aea544d5b4c9804739167f5115cf311b339e467

commit 8aea544d5b4c9804739167f5115cf311b339e467
Author:     Torsten Zuehlsdorff <tz@FreeBSD.org>
AuthorDate: 2021-05-05 11:41:59 +0000
Commit:     Torsten Zuehlsdorff <tz@FreeBSD.org>
CommitDate: 2021-05-05 11:44:15 +0000

    databases/php74-pdo_pgsql: Apply patch for PHP Bug 81002
    
    The last release introduces a bug, which causes BOOL values inserted into PostgreSQL
    converted to INT. This causes exceptions when tried.
    
    Since this is a serious issue, we apply the upstream patch
    until it gets official released
    
    Approved by:    madpilot
    Sponsored by:   Bounce Experts
    Differential Revision:  https://reviews.freebsd.org/D30117
---
 databases/php74-pdo_pgsql/Makefile                 |  2 +
 .../php74-pdo_pgsql/files/patch-pgsql__statement.c | 42 ++++++++++++
 .../files/patch-tests_bug__80892.phpt              | 80 ++++++++++++++++++++++
 3 files changed, 124 insertions(+)

diff --git a/databases/php74-pdo_pgsql/Makefile b/databases/php74-pdo_pgsql/Makefile
index e72354243c4a..890767046b75 100644
--- a/databases/php74-pdo_pgsql/Makefile
+++ b/databases/php74-pdo_pgsql/Makefile
@@ -1,5 +1,7 @@
 CATEGORIES=	databases
 
+PORTREVISION=	1
+
 MASTERDIR=	${.CURDIR}/../../lang/php74
 
 PKGNAMESUFFIX=	-pdo_pgsql
diff --git a/databases/php74-pdo_pgsql/files/patch-pgsql__statement.c b/databases/php74-pdo_pgsql/files/patch-pgsql__statement.c
new file mode 100644
index 000000000000..cbaeb53ea1a6
--- /dev/null
+++ b/databases/php74-pdo_pgsql/files/patch-pgsql__statement.c
@@ -0,0 +1,42 @@
+--- pgsql_statement.c.orig	2021-04-27 14:35:54 UTC
++++ pgsql_statement.c
+@@ -54,21 +54,8 @@
+ #define VARCHARLABEL "varchar"
+ #define VARCHAROID   1043
+ 
+-#define PG_INT32_MIN	(-0x7FFFFFFF-1)
+-#define PG_INT32_MAX	(0x7FFFFFFF)
+ 
+-#if defined(_MSC_VER)
+-# define strtoll(s, f, b) _atoi64(s)
+-#elif !defined(HAVE_STRTOLL)
+-# if defined(HAVE_ATOLL)
+-#  define strtoll(s, f, b) atoll(s)
+-# else
+-#  define strtoll(s, f, b) strtol(s, f, b)
+-# endif
+-#endif
+ 
+-
+-
+ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
+ {
+ 	pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
+@@ -403,16 +390,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, str
+ 						S->param_formats[param->paramno] = 0;
+ 					}
+ 
+-					if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_INT) {
+-						/* we need to check if the number requires bigints */
+-						long long val = strtoll(Z_STRVAL_P(parameter), NULL, 10);
+-
+-						if (val > PG_INT32_MAX || val < PG_INT32_MIN) {
+-							S->param_types[param->paramno] = INT8OID;
+-						} else {
+-							S->param_types[param->paramno] = INT4OID;
+-						}
+-					} else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
++					if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
+ 						S->param_types[param->paramno] = 0;
+ 						S->param_formats[param->paramno] = 1;
+ 					} else {
diff --git a/databases/php74-pdo_pgsql/files/patch-tests_bug__80892.phpt b/databases/php74-pdo_pgsql/files/patch-tests_bug__80892.phpt
new file mode 100644
index 000000000000..c926cacd0250
--- /dev/null
+++ b/databases/php74-pdo_pgsql/files/patch-tests_bug__80892.phpt
@@ -0,0 +1,80 @@
+--- tests/bug_80892.phpt.orig	2021-04-27 14:35:54 UTC
++++ tests/bug_80892.phpt
+@@ -1,77 +0,0 @@
+---TEST--
+-Bug #80892 PDO::PARAM_INT is treated the same as PDO::PARAM_STR
+---SKIPIF--
+-<?php
+-if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
+-require __DIR__ . '/config.inc';
+-require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
+-PDOTest::skip();
+-?>
+---FILE--
+-<?php
+-require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
+-
+-/** @var PDO $db */
+-$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
+-$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+-$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
+-
+-$db->exec("CREATE OR REPLACE FUNCTION bug80892 (x bigint) RETURNS varchar AS $$ SELECT 'bigint' $$ LANGUAGE sql");
+-$db->exec("CREATE OR REPLACE FUNCTION bug80892 (x int) RETURNS varchar AS $$ SELECT 'int' $$ LANGUAGE sql");
+-$db->exec("CREATE OR REPLACE FUNCTION bug80892 (x text) RETURNS varchar AS $$ SELECT 'text' $$ LANGUAGE sql");
+-
+-// Sanity check
+-var_dump($db->query("SELECT bug80892(2147483648)")->fetchColumn());
+-var_dump($db->query("SELECT bug80892(1)")->fetchColumn());
+-var_dump($db->query("SELECT bug80892('1')")->fetchColumn());
+-
+-// No binding
+-$stmt = $db->prepare("SELECT bug80892(?)");
+-$stmt->execute([1]);
+-var_dump($stmt->fetchColumn());
+-
+-// Bind int value as string
+-$stmt = $db->prepare("SELECT bug80892(?)");
+-$stmt->bindValue(1, 1, PDO::PARAM_STR);
+-$stmt->execute();
+-var_dump($stmt->fetchColumn());
+-
+-// Bind int value as int
+-$stmt = $db->prepare("SELECT bug80892(?)");
+-$stmt->bindValue(1, 1, PDO::PARAM_INT);
+-$stmt->execute();
+-var_dump($stmt->fetchColumn());
+-
+-// Bind string value as int
+-$stmt = $db->prepare("SELECT bug80892(?)");
+-$stmt->bindValue(1, '1', PDO::PARAM_INT);
+-$stmt->execute();
+-var_dump($stmt->fetchColumn());
+-
+-// Bind bigint string value as int
+-$stmt = $db->prepare("SELECT bug80892(?)");
+-$stmt->bindValue(1, '2147483648', PDO::PARAM_INT);
+-$stmt->execute();
+-var_dump($stmt->fetchColumn());
+-
+-// Bind negative bigint (string on 32bit) as int
+-$stmt = $db->prepare("SELECT bug80892(?)");
+-$stmt->bindValue(1, PHP_INT_SIZE == 4 ? '-33333333333' : -33333333333, PDO::PARAM_INT);
+-$stmt->execute();
+-var_dump($stmt->fetchColumn());
+-
+-$db->exec("DROP FUNCTION bug80892 (bigint)");
+-$db->exec("DROP FUNCTION bug80892 (int)");
+-$db->exec("DROP FUNCTION bug80892 (text)");
+-
+-?>
+---EXPECT--
+-string(6) "bigint"
+-string(3) "int"
+-string(4) "text"
+-string(4) "text"
+-string(4) "text"
+-string(3) "int"
+-string(3) "int"
+-string(6) "bigint"
+-string(6) "bigint"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105051144.145BiPtl097342>