Skip to content

Commit 3060dfd

Browse files
committed
Fix bug 68298 (PHP OCI8 OCI int overflow) (Senthil)
1 parent 1c0622a commit 3060dfd

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

ext/oci8/oci8_statement.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,15 +1139,22 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len,
11391139

11401140
case SQLT_INT:
11411141
case SQLT_NUM:
1142+
{
11421143
if (Z_TYPE_P(var) == IS_RESOURCE || Z_TYPE_P(var) == IS_OBJECT) {
11431144
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind");
11441145
return 1;
11451146
}
11461147
convert_to_long(var);
1148+
#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION > 10
1149+
bind_data = (ub8 *)&Z_LVAL_P(var);
1150+
value_sz = sizeof(ub8);
1151+
#else
11471152
bind_data = (ub4 *)&Z_LVAL_P(var);
11481153
value_sz = sizeof(ub4);
1154+
#endif
11491155
mode = OCI_DEFAULT;
1150-
break;
1156+
}
1157+
break;
11511158

11521159
case SQLT_LBI:
11531160
case SQLT_BIN:

ext/oci8/tests/bug68298.phpt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Bug #68298 (OCI int overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('oci8')) die ("skip no oci8 extension");
6+
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only");
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require(dirname(__FILE__).'/connect.inc');
12+
13+
$stmtarray = array(
14+
"DROP TABLE BUG68298",
15+
"CREATE TABLE BUG68298 (COL1 NUMBER(20))"
16+
);
17+
18+
oci8_test_sql_execute($c, $stmtarray);
19+
20+
$s = oci_parse($c, "INSERT INTO BUG68298 VALUES (:INTVALUE)");
21+
$intvalue = 1152921504606846975;
22+
oci_bind_by_name($s, ":INTVALUE", $intvalue, -1, SQLT_INT);
23+
oci_execute($s);
24+
25+
$s = oci_parse($c, "INSERT INTO BUG68298 VALUES (:INTVALUE)");
26+
$intvalue = -1152921504606846975;
27+
oci_bind_by_name($s, ":INTVALUE", $intvalue, -1, SQLT_INT);
28+
oci_execute($s);
29+
30+
31+
$s = oci_parse($c, "SELECT COL1 FROM BUG68298");
32+
oci_execute($s);
33+
oci_fetch_all($s, $r);
34+
var_dump($r);
35+
36+
$stmtarray = array("DROP TABLE BUG68298");
37+
oci8_test_sql_execute($c, $stmtarray);
38+
?>
39+
===DONE===
40+
<?php exit(0); ?>
41+
--EXPECTF--
42+
array(1) {
43+
["COL1"]=>
44+
array(2) {
45+
[0]=>
46+
string(19) "1152921504606846975"
47+
[1]=>
48+
string(20) "-1152921504606846975"
49+
}
50+
}
51+
===DONE===

0 commit comments

Comments
 (0)