summaryrefslogtreecommitdiff
path: root/ext/pgsql/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pgsql/tests')
-rw-r--r--ext/pgsql/tests/14pg_update.phpt3
-rw-r--r--ext/pgsql/tests/bug46408.phpt2
-rw-r--r--ext/pgsql/tests/bug71062.phpt39
-rw-r--r--ext/pgsql/tests/bug71998.phpt196
-rw-r--r--ext/pgsql/tests/bug72028.phpt52
-rw-r--r--ext/pgsql/tests/bug72195.phpt17
-rw-r--r--ext/pgsql/tests/bug72197.phpt35
7 files changed, 342 insertions, 2 deletions
diff --git a/ext/pgsql/tests/14pg_update.phpt b/ext/pgsql/tests/14pg_update.phpt
index d804574405..843dbac957 100644
--- a/ext/pgsql/tests/14pg_update.phpt
+++ b/ext/pgsql/tests/14pg_update.phpt
@@ -23,4 +23,5 @@ echo "Ok\n";
?>
--EXPECT--
UPDATE "php_pgsql_test" SET "num"=1234,"str"=E'ABC',"bin"=E'XYZ' WHERE "num"=1234;
-Ok \ No newline at end of file
+UPDATE "php_pgsql_test" SET "num='1234',"str='ABC',"bin='XYZ' WHERE "num='1234';
+Ok
diff --git a/ext/pgsql/tests/bug46408.phpt b/ext/pgsql/tests/bug46408.phpt
index bf84290907..5803347988 100644
--- a/ext/pgsql/tests/bug46408.phpt
+++ b/ext/pgsql/tests/bug46408.phpt
@@ -14,7 +14,7 @@ require_once('config.inc');
$dbh = pg_connect($conn_str);
setlocale(LC_ALL, 'hr_HR.utf-8', 'hr_HR');
-echo 3.5.PHP_EOL;
+echo 3.5 , "\n";
pg_query_params("SELECT $1::numeric", array(3.5));
pg_close($dbh);
diff --git a/ext/pgsql/tests/bug71062.phpt b/ext/pgsql/tests/bug71062.phpt
new file mode 100644
index 0000000000..56e350daad
--- /dev/null
+++ b/ext/pgsql/tests/bug71062.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Bug #71062 pg_convert() doesn't accept ISO 8601 for datatype timestamp
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+
+$table = "public.test_table_bug71062_bug71062";
+
+pg_query($db, "CREATE TABLE $table ( test_field TIMESTAMPTZ )");
+
+// ISO 8601 (with 'T' between date and time)
+$date_string_php_iso8601 = date_create('8 Dec 2015 5:38')->format(DateTime::ISO8601);
+
+// ISO 8601 with the 'T' removed
+$modified_format = 'Y-m-d H:i:sO';
+$date_string_modified_iso8601 = date_create('8 Dec 2015 5:38')->format($modified_format);
+
+printf("trying format %s \n", DateTime::ISO8601);
+pg_convert($db, $table, ['test_field' => $date_string_php_iso8601]);
+
+printf("trying format %s \n", $modified_format);
+pg_convert($db, $table, ['test_field' => $date_string_modified_iso8601]);
+
+print "done\n";
+
+pg_query($db, "DROP TABLE $table");
+
+?>
+==OK==
+--EXPECT--
+trying format Y-m-d\TH:i:sO
+trying format Y-m-d H:i:sO
+done
+==OK==
diff --git a/ext/pgsql/tests/bug71998.phpt b/ext/pgsql/tests/bug71998.phpt
new file mode 100644
index 0000000000..b9924166f9
--- /dev/null
+++ b/ext/pgsql/tests/bug71998.phpt
@@ -0,0 +1,196 @@
+--TEST--
+Bug #71998 Function pg_insert does not insert when column type = inet
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+// Kudos for the IP regex to
+// http://stackoverflow.com/a/17871737/3358424
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+
+pg_query("CREATE TABLE tmp_statistics (id integer NOT NULL, remote_addr inet);");
+
+$ips = array(
+ /* IPv4*/
+ "127.0.0.1",
+ "10.0.0.1",
+ "192.168.1.1",
+ "0.0.0.0",
+ "255.255.255.255",
+ "192.168.1.35/24",
+
+ /* IPv6 */
+ "::1",
+ "::10.2.3.4",
+ "::ffff:10.4.3.2",
+ "1:2:3:4:5:6:7:8",
+ "::ffff:10.0.0.1",
+ "::ffff:1.2.3.4",
+ "::ffff:0.0.0.0",
+ "1:2:3:4:5:6:77:88",
+ "::ffff:255.255.255.255",
+ "fe08::7:8",
+ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "::5:aef1:ffff/128",
+ "2001:4f8:3:ba::/112",
+
+);
+
+$bad = array(
+ /* bad */
+ "256.257.258.259",
+ "fe08::7:8interface",
+ "schnitzel",
+ "10002.3.4",
+ "1.2.3.4.5",
+ "256.0.0.0",
+ "260.0.0.0",
+);
+
+$ips = array_merge($ips, $bad);
+$i = 0;
+$errors = 0;
+foreach ($ips as $ip) {
+ $data = array("id" => ++$i, "remote_addr" => $ip);
+ $r = @pg_insert($db, 'tmp_statistics', $data);
+
+ if (!$r && in_array($ip, $bad)) {
+ $errors++;
+ //echo pg_last_error($db);
+ }
+
+ //pg_query($db, "INSERT INTO tmp_statistics (id, remote_addr) VALUES (2, '127.0.0.1')"); // OK, record inserted
+}
+
+
+$r = pg_query($db, "SELECT * FROM tmp_statistics");
+while (false != ($row = pg_fetch_row($r))) {
+ var_dump($row);
+}
+echo $errors, " errors catched\n";
+
+pg_query($db, "DROP TABLE tmp_statistics");
+pg_close($db);
+
+?>
+==DONE==
+--EXPECT--
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(9) "127.0.0.1"
+}
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(8) "10.0.0.1"
+}
+array(2) {
+ [0]=>
+ string(1) "3"
+ [1]=>
+ string(11) "192.168.1.1"
+}
+array(2) {
+ [0]=>
+ string(1) "4"
+ [1]=>
+ string(7) "0.0.0.0"
+}
+array(2) {
+ [0]=>
+ string(1) "5"
+ [1]=>
+ string(15) "255.255.255.255"
+}
+array(2) {
+ [0]=>
+ string(1) "6"
+ [1]=>
+ string(15) "192.168.1.35/24"
+}
+array(2) {
+ [0]=>
+ string(1) "7"
+ [1]=>
+ string(3) "::1"
+}
+array(2) {
+ [0]=>
+ string(1) "8"
+ [1]=>
+ string(10) "::10.2.3.4"
+}
+array(2) {
+ [0]=>
+ string(1) "9"
+ [1]=>
+ string(15) "::ffff:10.4.3.2"
+}
+array(2) {
+ [0]=>
+ string(2) "10"
+ [1]=>
+ string(15) "1:2:3:4:5:6:7:8"
+}
+array(2) {
+ [0]=>
+ string(2) "11"
+ [1]=>
+ string(15) "::ffff:10.0.0.1"
+}
+array(2) {
+ [0]=>
+ string(2) "12"
+ [1]=>
+ string(14) "::ffff:1.2.3.4"
+}
+array(2) {
+ [0]=>
+ string(2) "13"
+ [1]=>
+ string(14) "::ffff:0.0.0.0"
+}
+array(2) {
+ [0]=>
+ string(2) "14"
+ [1]=>
+ string(17) "1:2:3:4:5:6:77:88"
+}
+array(2) {
+ [0]=>
+ string(2) "15"
+ [1]=>
+ string(22) "::ffff:255.255.255.255"
+}
+array(2) {
+ [0]=>
+ string(2) "16"
+ [1]=>
+ string(9) "fe08::7:8"
+}
+array(2) {
+ [0]=>
+ string(2) "17"
+ [1]=>
+ string(39) "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
+}
+array(2) {
+ [0]=>
+ string(2) "18"
+ [1]=>
+ string(13) "::5:aef1:ffff"
+}
+array(2) {
+ [0]=>
+ string(2) "19"
+ [1]=>
+ string(19) "2001:4f8:3:ba::/112"
+}
+7 errors catched
+==DONE==
diff --git a/ext/pgsql/tests/bug72028.phpt b/ext/pgsql/tests/bug72028.phpt
new file mode 100644
index 0000000000..217a03abc7
--- /dev/null
+++ b/ext/pgsql/tests/bug72028.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Bug #72028 pg_query_params(): NULL converts to empty string
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+// create test table
+
+include('config.inc');
+
+$conn = pg_connect($conn_str);
+
+$table = "bug72028_" . md5(uniqid(time()));
+
+pg_query("CREATE TABLE $table (value TEXT, details TEXT);");
+
+$sql = "INSERT INTO $table (value, details) VALUES ($1, $2)";
+
+$params = array(null, "insert before looping with a reference");
+$result = pg_query_params($conn, $sql, $params);
+
+$params2 = array(null, "insert after looping with a reference");
+foreach ($params2 as &$p) {
+ // doing nothing
+}
+unset($p);
+
+$result = pg_query_params($conn, $sql, $params2);
+
+$r = pg_query("SELECT * FROM $table");
+while (false !== ($i = pg_fetch_assoc($r))) {
+ var_dump($i);
+}
+
+pg_query("DROP TABLE $table");
+
+?>
+==DONE==
+--EXPECT--
+array(2) {
+ ["value"]=>
+ NULL
+ ["details"]=>
+ string(38) "insert before looping with a reference"
+}
+array(2) {
+ ["value"]=>
+ NULL
+ ["details"]=>
+ string(37) "insert after looping with a reference"
+}
+==DONE==
diff --git a/ext/pgsql/tests/bug72195.phpt b/ext/pgsql/tests/bug72195.phpt
new file mode 100644
index 0000000000..34735d31f4
--- /dev/null
+++ b/ext/pgsql/tests/bug72195.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #72195 (pg_pconnect/pg_connect cause use-after-free)
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+$val = [];
+$var1 = $val;
+printf("%x\n", count($val));
+@pg_pconnect($var1, "2", "3", "4");
+$var1 = "";
+tempnam(sys_get_temp_dir(), 'ABCDEFGHI');
+printf("%x\n", count($val));
+?>
+--EXPECT--
+0
+0
diff --git a/ext/pgsql/tests/bug72197.phpt b/ext/pgsql/tests/bug72197.phpt
new file mode 100644
index 0000000000..2ce15bdaf4
--- /dev/null
+++ b/ext/pgsql/tests/bug72197.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Bug #72197 pg_lo_create arbitrary read
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+/* This shouldn't crash. */
+$var1=-32768;
+$var2="12";
+pg_lo_create($var1, $var2);
+
+/* This should work correctly. */
+include('config.inc');
+
+/* Check with explicit link. */
+$conn = pg_connect($conn_str);
+pg_query($conn, "BEGIN");
+$oid = pg_lo_create($conn);
+var_dump($oid);
+
+/* Check with default link */
+$oid = pg_lo_create();
+var_dump($oid);
+
+/* don't commit */
+pg_query($conn, "ROLLBACK");
+pg_close($conn);
+?>
+==DONE==
+--EXPECTF--
+Warning: pg_lo_create(): supplied resource is not a valid PostgreSQL link resource in %sbug72197.php on line %d%w
+int(%d)
+int(%d)
+==DONE==
+