Skip to content

Commit 3090c88

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79038: PDOStatement::nextRowset() leaks column values
2 parents 8db8d66 + 08073b0 commit 3090c88

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ PHP NEWS
2929
. Fixed bug #79257 (Duplicate named groups (?J) prefer last alternative even
3030
if not matched). (Nikita)
3131

32+
- PDO_ODBC:
33+
. Fixed bug #79038 (PDOStatement::nextRowset() leaks column values). (cmb)
34+
3235
- Standard:
3336
. Fixed bug #79254 (getenv() w/o arguments not showing changes). (cmb)
3437

ext/pdo_odbc/odbc_stmt.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ static void free_cols(pdo_stmt_t *stmt, pdo_odbc_stmt *S)
126126
if (S->cols) {
127127
int i;
128128

129-
for (i = 0; i < stmt->column_count; i++) {
129+
for (i = 0; i < S->col_count; i++) {
130130
if (S->cols[i].data) {
131131
efree(S->cols[i].data);
132132
}
133133
}
134134
efree(S->cols);
135135
S->cols = NULL;
136+
S->col_count = 0;
136137
}
137138
}
138139

@@ -262,14 +263,14 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt)
262263
SQLRowCount(S->stmt, &row_count);
263264
stmt->row_count = row_count;
264265

265-
if (!stmt->executed) {
266+
if (S->cols == NULL) {
266267
/* do first-time-only definition of bind/mapping stuff */
267268
SQLSMALLINT colcount;
268269

269270
/* how many columns do we have ? */
270271
SQLNumResultCols(S->stmt, &colcount);
271272

272-
stmt->column_count = (int)colcount;
273+
stmt->column_count = S->col_count = (int)colcount;
273274
S->cols = ecalloc(colcount, sizeof(pdo_odbc_column));
274275
S->going_long = 0;
275276
}
@@ -847,13 +848,25 @@ static int odbc_stmt_next_rowset(pdo_stmt_t *stmt)
847848
free_cols(stmt, S);
848849
/* how many columns do we have ? */
849850
SQLNumResultCols(S->stmt, &colcount);
850-
stmt->column_count = (int)colcount;
851+
stmt->column_count = S->col_count = (int)colcount;
851852
S->cols = ecalloc(colcount, sizeof(pdo_odbc_column));
852853
S->going_long = 0;
853854

854855
return 1;
855856
}
856857

858+
static int odbc_stmt_close_cursor(pdo_stmt_t *stmt)
859+
{
860+
SQLRETURN rc;
861+
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
862+
863+
rc = SQLCloseCursor(S->stmt);
864+
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
865+
return 0;
866+
}
867+
return 1;
868+
}
869+
857870
const struct pdo_stmt_methods odbc_stmt_methods = {
858871
odbc_stmt_dtor,
859872
odbc_stmt_execute,
@@ -864,5 +877,6 @@ const struct pdo_stmt_methods odbc_stmt_methods = {
864877
odbc_stmt_set_param,
865878
odbc_stmt_get_attr, /* get attr */
866879
NULL, /* get column meta */
867-
odbc_stmt_next_rowset
880+
odbc_stmt_next_rowset,
881+
odbc_stmt_close_cursor
868882
};

ext/pdo_odbc/php_pdo_odbc_int.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ typedef struct {
151151
zend_ulong convbufsize;
152152
unsigned going_long:1;
153153
unsigned assume_utf8:1;
154-
unsigned _spare:30;
154+
signed col_count:16;
155+
unsigned _spare:14;
155156
} pdo_odbc_stmt;
156157

157158
typedef struct {

0 commit comments

Comments
 (0)