Skip to content

Commit 98049e8

Browse files
committed
Fix #81252: PDO_ODBC doesn't account for SQL_NO_TOTAL
If `P->len` is negative (not only when it is `SQL_NULL_DATA`), we must not go on, because the following code can't deal with that. This means that the output parameter will be set to `NULL` without any indication what went wrong, but it's still better than crashing. Closes GH-7295.
1 parent d26069a commit 98049e8

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ PHP NEWS
1313
- CGI:
1414
. Fixed bug #80849 (HTTP Status header truncation). (cmb)
1515

16+
- PDO_ODBC:
17+
. Fixed bug #81252 (PDO_ODBC doesn't account for SQL_NO_TOTAL). (cmb)
18+
1619
- Shmop:
1720
. Fixed bug #81283 (shmop can't read beyond 2147483647 bytes). (cmb, Nikita)
1821

ext/pdo_odbc/odbc_stmt.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,26 +501,23 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p
501501
zval_ptr_dtor(parameter);
502502
ZVAL_NULL(parameter);
503503

504-
switch (P->len) {
505-
case SQL_NULL_DATA:
506-
break;
507-
default:
508-
switch (pdo_odbc_ucs22utf8(stmt, P->is_unicode, P->outbuf, P->len, &ulen)) {
509-
case PDO_ODBC_CONV_FAIL:
510-
/* something fishy, but allow it to come back as binary */
511-
case PDO_ODBC_CONV_NOT_REQUIRED:
512-
srcbuf = P->outbuf;
513-
srclen = P->len;
514-
break;
515-
case PDO_ODBC_CONV_OK:
516-
srcbuf = S->convbuf;
517-
srclen = ulen;
518-
break;
519-
}
504+
if (P->len >= 0) {
505+
switch (pdo_odbc_ucs22utf8(stmt, P->is_unicode, P->outbuf, P->len, &ulen)) {
506+
case PDO_ODBC_CONV_FAIL:
507+
/* something fishy, but allow it to come back as binary */
508+
case PDO_ODBC_CONV_NOT_REQUIRED:
509+
srcbuf = P->outbuf;
510+
srclen = P->len;
511+
break;
512+
case PDO_ODBC_CONV_OK:
513+
srcbuf = S->convbuf;
514+
srclen = ulen;
515+
break;
516+
}
520517

521-
ZVAL_NEW_STR(parameter, zend_string_alloc(srclen, 0));
522-
memcpy(Z_STRVAL_P(parameter), srcbuf, srclen);
523-
Z_STRVAL_P(parameter)[Z_STRLEN_P(parameter)] = '\0';
518+
ZVAL_NEW_STR(parameter, zend_string_alloc(srclen, 0));
519+
memcpy(Z_STRVAL_P(parameter), srcbuf, srclen);
520+
Z_STRVAL_P(parameter)[Z_STRLEN_P(parameter)] = '\0';
524521
}
525522
}
526523
return 1;

0 commit comments

Comments
 (0)