Skip to content

Fix GH-9372: HY010 when binding overlong parameter #9541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static int odbc_stmt_dtor(pdo_stmt_t *stmt)

static int odbc_stmt_execute(pdo_stmt_t *stmt)
{
RETCODE rc;
RETCODE rc, rc1;
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
char *buf = NULL;
SQLLEN row_count = -1;
Expand Down Expand Up @@ -192,11 +192,17 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt)
Z_STRLEN_P(parameter),
&ulen)) {
case PDO_ODBC_CONV_NOT_REQUIRED:
SQLPutData(S->stmt, Z_STRVAL_P(parameter),
rc1 = SQLPutData(S->stmt, Z_STRVAL_P(parameter),
Z_STRLEN_P(parameter));
if (rc1 != SQL_SUCCESS && rc1 != SQL_SUCCESS_WITH_INFO) {
rc = rc1;
}
break;
case PDO_ODBC_CONV_OK:
SQLPutData(S->stmt, S->convbuf, ulen);
rc1 = SQLPutData(S->stmt, S->convbuf, ulen);
if (rc1 != SQL_SUCCESS && rc1 != SQL_SUCCESS_WITH_INFO) {
rc = rc1;
}
break;
case PDO_ODBC_CONV_FAIL:
pdo_odbc_stmt_error("error converting input string");
Expand Down Expand Up @@ -233,7 +239,10 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt)
if (len == 0) {
break;
}
SQLPutData(S->stmt, buf, len);
rc1 = SQLPutData(S->stmt, buf, len);
if (rc1 != SQL_SUCCESS && rc1 != SQL_SUCCESS_WITH_INFO) {
rc = rc1;
}
} while (1);
}
}
Expand Down
52 changes: 52 additions & 0 deletions ext/pdo_odbc/tests/gh9372.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
Bug GH-9372 (HY010 when binding overlong parameter)
--EXTENSIONS--
pdo_odbc
--SKIPIF--
<?php
require 'ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
// Executing the statements fails with some drivers, but not others.
// The test is written in a way to always pass, unless the execution
// fails with a different code than 22001 (String data, right truncation).

require 'ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$db->exec("CREATE TABLE gh9372 (col VARCHAR(10))");
$db->exec("INSERT INTO gh9372 VALUES ('something')");

$stmt = $db->prepare("SELECT * FROM gh9372 WHERE col = ?");
$stmt->bindValue(1, 'something else');
try {
$stmt->execute();
} catch (PDOException $ex) {
if ($ex->getCode() !== "22001") {
var_dump($ex->getMessage());
}
}

$stmt = $db->prepare("SELECT * FROM gh9372 WHERE col = ?");
$stream = fopen("php://memory", "w+");
fwrite($stream, 'something else');
rewind($stream);
$stmt->bindvalue(1, $stream, PDO::PARAM_LOB);
try {
$stmt->execute();
} catch (PDOException $ex) {
if ($ex->getCode() !== "22001") {
var_dump($ex->getMessage());
}
}
?>
--CLEAN--
<?php
require 'ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
$db->exec("DROP TABLE gh9372");
?>
--EXPECT--