Skip to content

Commit c4c8d6c

Browse files
committed
Fix missing and inconsistent error check on SQLAllocHandle
* Missing check: SQLAllocHandle() for the environment wasn't checked in pdo_odbc_handle_factory(). Add a check similar to the other ones for SQLAllocHandle(). * Inconsistent check: one of the SQLAllocHandle() calls wasn't checked for SQL_SUCCESS_WITH_INFO. However, looking at the other uses and the documentation we should probably check this as well. Furthermore, since there was a mix of "SQLAllocHandle: reason" and "SQLAllocHandle (reason)" in the error reporting, I made them consistently use the first option as that seems to be the most used for error reporting in this file. Closes GH-10740.
1 parent bdf2f72 commit c4c8d6c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ PHP NEWS
2424
- OpenSSL:
2525
. Add missing error checks on file writing functions. (nielsdos)
2626

27+
- PDO ODBC:
28+
. Fixed missing and inconsistent error checks on SQLAllocHandle. (nielsdos)
29+
2730
- Phar:
2831
. Fixed bug GH-10766 (PharData archive created with Phar::Zip format does
2932
not keep files metadata (datetime)). (nielsdos)

ext/pdo_odbc/odbc_driver.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static zend_long odbc_handle_doer(pdo_dbh_t *dbh, const zend_string *sql)
220220
PDO_ODBC_HSTMT stmt;
221221

222222
rc = SQLAllocHandle(SQL_HANDLE_STMT, H->dbc, &stmt);
223-
if (rc != SQL_SUCCESS) {
223+
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
224224
pdo_odbc_drv_error("SQLAllocHandle: STMT");
225225
return -1;
226226
}
@@ -439,7 +439,12 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
439439

440440
dbh->driver_data = H;
441441

442-
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &H->env);
442+
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &H->env);
443+
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
444+
pdo_odbc_drv_error("SQLAllocHandle: ENV");
445+
goto fail;
446+
}
447+
443448
rc = SQLSetEnvAttr(H->env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
444449

445450
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
@@ -459,7 +464,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
459464

460465
rc = SQLAllocHandle(SQL_HANDLE_DBC, H->env, &H->dbc);
461466
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
462-
pdo_odbc_drv_error("SQLAllocHandle (DBC)");
467+
pdo_odbc_drv_error("SQLAllocHandle: DBC");
463468
goto fail;
464469
}
465470

0 commit comments

Comments
 (0)