From 64dae604616e35df4c5cf9fde09f56ebee0632ac Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 16 Dec 2024 15:43:52 -0400 Subject: [PATCH 1/2] Don't use NTS for returned values via env attr User issue on IBM i may involve the driver not returning properly null terminating strings correctly. The get_col handler seems to handle this case, so let's do a CI run to see how badly this explodes on LUW. --- ibm_driver.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ibm_driver.c b/ibm_driver.c index c4d0fc6..74a9cc7 100644 --- a/ibm_driver.c +++ b/ibm_driver.c @@ -1088,6 +1088,8 @@ static int dbh_connect(pdo_dbh_t *dbh, zval *driver_options) rc = SQLSetEnvAttr((SQLHENV)conn_res->henv, SQL_ATTR_UTF8, (SQLPOINTER)(intptr_t)SQL_TRUE, 0); } #endif /* PASE */ + /* forced fixed length strings to be returned */ + rc = SQLSetEnvAttr((SQLHENV)conn_res->henv, SQL_ATTR_OUTPUT_NTS, (SQLPOINTER)(intptr_t)SQL_FALSE, SQL_IS_INTEGER); /* now an actual connection handle */ rc = SQLAllocHandle(SQL_HANDLE_DBC, conn_res->henv, &(conn_res->hdbc)); From c070c869c79d5cd1e4da7b0d918af4b04a68c63c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Wed, 18 Dec 2024 11:01:43 -0400 Subject: [PATCH 2/2] Don't assume NTS for SQLGetInfo I think this is Informix detritus anyways - there's a dedicated PDO driver for that, so maybe we should be cleaning this up... --- ibm_statement.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ibm_statement.c b/ibm_statement.c index 21dbf40..93f9872 100644 --- a/ibm_statement.c +++ b/ibm_statement.c @@ -1906,10 +1906,12 @@ int record_last_insert_id( pdo_stmt_t * stmt, pdo_dbh_t *dbh, SQLHANDLE hstmt) long int returnValue; conn_handle *conn_res = (conn_handle *) dbh->driver_data; char id[ MAX_IDENTITY_DIGITS ] = ""; - char server[MAX_DBMS_IDENTIFIER_NAME]; + char server[MAX_DBMS_IDENTIFIER_NAME + 1]; + SQLSMALLINT server_name_length = 0; - rc = SQLGetInfo(conn_res->hdbc, SQL_DBMS_NAME, (SQLPOINTER)server, MAX_DBMS_IDENTIFIER_NAME, NULL); + rc = SQLGetInfo(conn_res->hdbc, SQL_DBMS_NAME, (SQLPOINTER)server, MAX_DBMS_IDENTIFIER_NAME, &server_name_length); check_dbh_error(rc, "SQLGetInfo"); + server[server_name_length] = '\0'; if( strncmp( server, "IDS", 3 ) == 0 ) { rc = SQLGetStmtAttr( (SQLHSTMT)hstmt, SQL_ATTR_GET_GENERATED_VALUE, (SQLPOINTER)id, MAX_IDENTITY_DIGITS, NULL );