Skip to content

Commit

Permalink
Fix bug 68298 (PHP OCI8 OCI int overflow) (Senthil)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbj committed Nov 6, 2015
1 parent 27aef97 commit 049325c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/oci8/oci8_statement.c
Expand Up @@ -1149,8 +1149,13 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l
return 1;
}
convert_to_long(var);
#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION > 10
bind_data = (ub8 *)&Z_LVAL_P(var);
value_sz = sizeof(ub8);
#else
bind_data = (ub4 *)&Z_LVAL_P(var);
value_sz = sizeof(ub4);
#endif
mode = OCI_DEFAULT;
break;

Expand Down
51 changes: 51 additions & 0 deletions ext/oci8/tests/bug68298.phpt
@@ -0,0 +1,51 @@
--TEST--
Bug #68298 (OCI int overflow)
--SKIPIF--
<?php
if (!extension_loaded('oci8')) die ("skip no oci8 extension");
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only");
?>
--FILE--
<?php

require(dirname(__FILE__).'/connect.inc');

$stmtarray = array(
"DROP TABLE BUG68298",
"CREATE TABLE BUG68298 (COL1 NUMBER(20))"
);

oci8_test_sql_execute($c, $stmtarray);

$s = oci_parse($c, "INSERT INTO BUG68298 VALUES (:INTVALUE)");
$intvalue = 1152921504606846975;
oci_bind_by_name($s, ":INTVALUE", $intvalue, -1, SQLT_INT);
oci_execute($s);

$s = oci_parse($c, "INSERT INTO BUG68298 VALUES (:INTVALUE)");
$intvalue = -1152921504606846975;
oci_bind_by_name($s, ":INTVALUE", $intvalue, -1, SQLT_INT);
oci_execute($s);


$s = oci_parse($c, "SELECT COL1 FROM BUG68298");
oci_execute($s);
oci_fetch_all($s, $r);
var_dump($r);

$stmtarray = array("DROP TABLE BUG68298");
oci8_test_sql_execute($c, $stmtarray);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(1) {
["COL1"]=>
array(2) {
[0]=>
string(19) "1152921504606846975"
[1]=>
string(20) "-1152921504606846975"
}
}
===DONE===

0 comments on commit 049325c

Please sign in to comment.