Skip to content

Commit cda0dd6

Browse files
committed
change to separate by 256 bytes, when C->fetched_len == SQL_NO_TOTAL
1 parent d475fb8 commit cda0dd6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ext/pdo_odbc/odbc_stmt.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,24 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
684684
* The extension previously tried getting it in 256
685685
* byte blocks, but this could have created trouble
686686
* with some drivers.
687+
*
688+
* However, depending on the driver, fetched_len may
689+
* not contain the number of bytes and SQL_NO_TOTAL
690+
* may be passed.
691+
* In that case, the operation will be the same as
692+
* before, dividing the data into 256-byte blocks.
687693
*/
688-
SQLLEN to_fetch_len = orig_fetched_len + 1; /* for 0 at end */
694+
SQLLEN to_fetch_len;
695+
size_t used;
696+
if (C->fetched_len == SQL_NO_TOTAL) {
697+
to_fetch_len = 256;
698+
used = 255; /* not 256; the driver NUL terminated the buffer */
699+
} else {
700+
to_fetch_len = orig_fetched_len + 1; /* for 0 at end */
701+
used = orig_fetched_len; /* not n + 1; the driver NUL terminated the buffer */
702+
}
689703
char *buf2 = emalloc(to_fetch_len);
690704
zend_string *str = zend_string_init(C->data, to_fetch_len, 0);
691-
size_t used = orig_fetched_len; /* not n + 1; the driver NUL terminated the buffer */
692705

693706
do {
694707
C->fetched_len = 0;

0 commit comments

Comments
 (0)