[php-src] master: Merge branch 'PHP-8.5'
| From: | Ilia Alshanetsky | Date: | Mon, 07 Sep 2026 22:45:51 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141124@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-09-07T18:42:07-04:00
Commit: https://github.com/php/php-src/commit/1364de0472b859917f5bc0be9193bd8068fc2061
Raw diff: https://github.com/php/php-src/commit/1364de0472b859917f5bc0be9193bd8068fc2061.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
odbc: check SQLColAttribute return codes in the field info functions
Changed paths:
M NEWS
M ext/odbc/php_odbc.c
Diff:
diff --git a/NEWS b/NEWS
index cae4c0bbcc60..1b2e879fcaf5 100644
--- a/NEWS
+++ b/NEWS
@@ -52,6 +52,11 @@ PHP NEWS
replacement when a \k<name> backref has no closing delimiter.
(Ilia Alshanetsky)
+- ODBC:
+ . Fixed odbc_field_len(), odbc_field_scale() and odbc_field_type()
+ returning uninitialized memory when SQLColAttribute fails.
+ (Ilia Alshanetsky)
+
- PCNTL:
. Fixed the declared signature of pcntl_signal(), whose $restart_syscalls
argument accepts null and defaults to it. (lacatoire)
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index 5a1a20e10686..d1cf2716cfca 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -676,6 +676,7 @@ void odbc_bindcols(odbc_result *result)
result->values[i].value_max_len = 0;
colfieldid = SQL_COLUMN_DISPLAY_SIZE;
+ result->values[i].name[0] = '\0';
rc = SQLColAttribute(result->stmt, (SQLUSMALLINT)(i+1), SQL_DESC_NAME,
result->values[i].name, sizeof(result->values[i].name), &colnamelen, 0);
result->values[i].coltype = 0;
@@ -784,10 +785,30 @@ void odbc_transact(INTERNAL_FUNCTION_PARAMETERS, int type)
}
/* }}} */
+static void odbc_colattribute_failed(odbc_result *result, zend_long pv_num)
+{
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
+ SQLINTEGER diag_error;
+ SQLCHAR diag_state[6];
+ SQLCHAR diag_text[128];
+
+ memset(diag_state, '\0', sizeof(diag_state));
+ memset(diag_text, '\0', sizeof(diag_text));
+ if (SQL_SUCCESS == SQLGetDiagRec(SQL_HANDLE_STMT, result->stmt, 1, diag_state, &diag_error,
diag_text, sizeof(diag_text), NULL)) {
+ diag_state[sizeof(diag_state) - 1] = '\0';
+ diag_text[sizeof(diag_text) - 1] = '\0';
+ php_error_docref(NULL, E_WARNING, "SQLColAttribute failed for field #%d: [%s] %s",
(int)pv_num, diag_state, diag_text);
+ return;
+ }
+#endif
+ php_error_docref(NULL, E_WARNING, "SQLColAttribute failed for field #%d", (int)pv_num);
+}
+
/* {{{ odbc_column_lengths */
void odbc_column_lengths(INTERNAL_FUNCTION_PARAMETERS, int type)
{
odbc_result *result;
+ RETCODE rc;
SQLLEN len;
zend_long pv_num;
@@ -813,7 +834,11 @@ void odbc_column_lengths(INTERNAL_FUNCTION_PARAMETERS, int type)
RETURN_FALSE;
}
- SQLColAttribute(result->stmt, (SQLUSMALLINT)pv_num, (SQLUSMALLINT)
(type?SQL_COLUMN_SCALE:SQL_COLUMN_PRECISION), NULL, 0, NULL, &len);
+ rc = SQLColAttribute(result->stmt, (SQLUSMALLINT)pv_num, (SQLUSMALLINT)(type ? SQL_COLUMN_SCALE
: SQL_COLUMN_PRECISION), NULL, 0, NULL, &len);
+ if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
+ odbc_colattribute_failed(result, pv_num);
+ len = 0;
+ }
RETURN_LONG(len);
}
@@ -2315,6 +2340,7 @@ PHP_FUNCTION(odbc_field_type)
odbc_result *result;
char tmp[32];
SQLSMALLINT tmplen;
+ RETCODE rc;
zend_long pv_num;
ZEND_PARSE_PARAMETERS_START(2, 2)
@@ -2339,7 +2365,13 @@ PHP_FUNCTION(odbc_field_type)
RETURN_FALSE;
}
- SQLColAttribute(result->stmt, (SQLUSMALLINT)pv_num, SQL_COLUMN_TYPE_NAME, tmp, 31, &tmplen,
NULL);
+ tmp[0] = '\0';
+ rc = SQLColAttribute(result->stmt, (SQLUSMALLINT)pv_num, SQL_COLUMN_TYPE_NAME, tmp, sizeof(tmp)
- 1, &tmplen, NULL);
+ if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
+ odbc_colattribute_failed(result, pv_num);
+ RETURN_FALSE;
+ }
+
RETURN_STRING(tmp);
}
/* }}} */