From: Antony Dovgal Date: Wed, 9 Aug 2006 12:13:30 +0000 (+0000) Subject: fix #38161 (oci_bind_by_name() returns garbage when Oracle didn't set the variable) X-Git-Tag: RELEASE_1_0_0RC1~2012 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=225fb6a51ac7334cbe84a303c6edba6305e00265;p=php fix #38161 (oci_bind_by_name() returns garbage when Oracle didn't set the variable) --- diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 926cc5ca77..19f2d2c376 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -826,9 +826,11 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, case SQLT_LNG: case SQLT_CHR: /* this is the default case when type was not specified */ - convert_to_string(var); + if (Z_TYPE_P(var) != IS_NULL) { + convert_to_string(var); + } if (maxlength == -1) { - value_sz = Z_STRLEN_P(var); + value_sz = (Z_TYPE_P(var) == IS_STRING) ? Z_STRLEN_P(var) : 0; } else { value_sz = maxlength; @@ -1003,7 +1005,7 @@ sb4 php_oci_bind_out_callback( zval_dtor(val); Z_STRLEN_P(val) = PHP_OCI_PIECE_SIZE; /* 64K-1 is max XXX */ - Z_STRVAL_P(val) = emalloc(Z_STRLEN_P(phpbind->zval)); + Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(phpbind->zval) + 1); /* XXX we assume that zend-zval len has 4 bytes */ *alenpp = (ub4*) &Z_STRLEN_P(phpbind->zval); diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h index 18e739f1cd..346abe3ce4 100644 --- a/ext/oci8/php_oci8_int.h +++ b/ext/oci8/php_oci8_int.h @@ -186,7 +186,7 @@ typedef struct { /* php_oci_bind {{{ */ long max_length; long type; } array; - sb2 indicator; /* */ + sb2 indicator; /* -1 means NULL */ ub2 retcode; /* */ } php_oci_bind; /* }}} */ diff --git a/ext/oci8/tests/bug37581.phpt b/ext/oci8/tests/bug37581.phpt new file mode 100644 index 0000000000..ec86c51959 --- /dev/null +++ b/ext/oci8/tests/bug37581.phpt @@ -0,0 +1,69 @@ +--TEST-- +Bug #37581 (oci_bind_array_by_name clobbers input array when using SQLT_AFC, AVC) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +array(5) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" +} +array(5) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" +} +Done diff --git a/ext/oci8/tests/bug38161.phpt b/ext/oci8/tests/bug38161.phpt new file mode 100644 index 0000000000..27cfafdc8f --- /dev/null +++ b/ext/oci8/tests/bug38161.phpt @@ -0,0 +1,30 @@ +--TEST-- +bug #38161 (oci_bind_by_name() returns garbage when Oracle didn't set the variable) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +NULL +int(0) +Done