summaryrefslogtreecommitdiff
path: root/ext/sybase_ct/php_sybase_ct.c
diff options
context:
space:
mode:
authorTimm Friebe <thekid@php.net>2010-06-16 09:34:11 +0000
committerTimm Friebe <thekid@php.net>2010-06-16 09:34:11 +0000
commitaa71d4e2f50b6b94285d2e35d05e40727614dac2 (patch)
tree25c027d0a2226f16919894150070810e3985cbd3 /ext/sybase_ct/php_sybase_ct.c
parentb95170580c452934898c32dc6192eace99cbb22d (diff)
downloadphp-git-aa71d4e2f50b6b94285d2e35d05e40727614dac2.tar.gz
- Fixed segmentation fault when reading rows
# Problem surfaces when using FreeTDS, ASE 12.5 and reading text fields # with NULL values. This is essentially a workaround for a bug in Free- # TDS which is not setting the NULL indicators correctly, but provides # a protection against possible segfaults if any other driver ever does # this again:-)
Diffstat (limited to 'ext/sybase_ct/php_sybase_ct.c')
-rw-r--r--ext/sybase_ct/php_sybase_ct.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/sybase_ct/php_sybase_ct.c b/ext/sybase_ct/php_sybase_ct.c
index 43014e60cf..005aa1c48f 100644
--- a/ext/sybase_ct/php_sybase_ct.c
+++ b/ext/sybase_ct/php_sybase_ct.c
@@ -1247,8 +1247,17 @@ static int php_sybase_fetch_result_row(sybase_result *result, int numrows TSRMLS
}
default: {
- /* This indicates anything else, return it as string */
- ZVAL_STRINGL(&result->data[i][j], result->tmp_buffer[j], result->lengths[j]- 1, 1);
+ /* This indicates anything else, return it as string
+ * FreeTDS doesn't correctly set result->indicators[j] correctly
+ * for NULL fields in some version in conjunction with ASE 12.5
+ * but instead sets result->lengths[j] to 0, which would lead to
+ * a negative memory allocation (and thus a segfault).
+ */
+ if (result->lengths[j] < 1) {
+ ZVAL_NULL(&result->data[i][j]);
+ } else {
+ ZVAL_STRINGL(&result->data[i][j], result->tmp_buffer[j], result->lengths[j]- 1, 1);
+ }
break;
}
}