com php-src: Merge remote-tracking branch 'origin/master' into str_size_and_int64: ext/mysqlnd/mysqlnd_ps_co dec.c ext/pgsql/pgsql.c
| From: | Anatol Belski | Date: | Tue, 14 Jan 2014 08:10:38 +0000 |
| Subject: | com php-src: Merge remote-tracking branch 'origin/master' into str_size_and_int64: ext/mysqlnd/mysqlnd_ps_co dec.c ext/pgsql/pgsql.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-75613@lists.php.net to get a copy of this message | ||
Commit: 28c917923d625e44326e62aa4f9872f10aaa531d
Author: Anatol Belski <ab@php.net> Tue, 14 Jan 2014 09:10:38 +0100
Parents: 614a69fe1d02501ffd619beca82b8750e8d02d09 681e1a5ce0d8b4bcadf40cd608c5f72f9ad73394
Branches: str_size_and_int64
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=28c917923d625e44326e62aa4f9872f10aaa531d
Log:
Merge remote-tracking branch 'origin/master' into str_size_and_int64
Conflicts:
ext/mysqlnd/mysqlnd_ps_codec.c
Changed paths:
MM ext/mysqlnd/mysqlnd_ps_codec.c
MM ext/pgsql/pgsql.c
diff --cc ext/mysqlnd/mysqlnd_ps_codec.c index 665d7e2,e08bb26..4b2aaee --- a/ext/mysqlnd/mysqlnd_ps_codec.c +++ b/ext/mysqlnd/mysqlnd_ps_codec.c @@@ -544,56 -561,29 +561,29 @@@ mysqlnd_stmt_execute_check_n_enlarge_bu /* }}} */ - /* {{{ mysqlnd_stmt_execute_store_params */ + /* {{{ mysqlnd_stmt_execute_prepare_param_types */ static enum_func_status - mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar **p, size_t * buf_len TSRMLS_DC) + mysqlnd_stmt_execute_prepare_param_types(MYSQLND_STMT_DATA * stmt, zval *** copies_param, int * resend_types_next_time TSRMLS_DC) { - MYSQLND_STMT_DATA * stmt = s->data; - php_uint_t i = 0; - zend_uchar * provided_buffer = *buf; - size_t data_size = 0; - zval **copies = NULL;/* if there are different types */ - enum_func_status ret = FAIL; - int resend_types_next_time = 0; - size_t null_byte_offset; - - DBG_ENTER("mysqlnd_stmt_execute_store_params"); - - { - php_uint_t null_count = (stmt->param_count + 7) / 8; - if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, null_count TSRMLS_CC)) { - SET_OOM_ERROR(*stmt->error_info); - goto end; - } - /* put `null` bytes */ - null_byte_offset = *p - *buf; - memset(*p, 0, null_count); - *p += null_count; - } - - /* 1. Store type information */ - /* - check if need to send the types even if stmt->send_types_to_server is 0. This is because - if we send "i" (42) then the type will be int and the server will expect int. However, if next - time we try to send > PHP_INT_MAX, the conversion to string will send a string and the server - won't expect it and interpret the value as 0. Thus we need to resend the types, if any such values - occur, and force resend for the next execution. - */ - unsigned int i; ++ php_uint_t i; + DBG_ENTER("mysqlnd_stmt_execute_prepare_param_types"); for (i = 0; i < stmt->param_count; i++) { short current_type = stmt->param_bind[i].type; if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) { + zval ** copies; /* always copy the var, because we do many conversions */ - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG && + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_INT && - PASS != mysqlnd_stmt_copy_it(&copies, stmt->param_bind[i].zv, stmt->param_count, i TSRMLS_CC)) + PASS != mysqlnd_stmt_copy_it(copies_param, stmt->param_bind[i].zv, stmt->param_count, i TSRMLS_CC)) { SET_OOM_ERROR(*stmt->error_info); goto end; } + copies = *copies_param; /* if it doesn't fit in a long send it as a string. - Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX + Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > PHP_INT_MAX */ - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) { + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_INT) { zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv; /* Because converting to double and back to long can lead @@@ -609,69 -599,79 +599,79 @@@ /* if it doesn't fit in a long send it as a string. - Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX + Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > PHP_INT_MAX We do transformation here, which will be used later when sending types. The code later relies on this. */ - if (Z_DVAL_P(tmp_data_copy) > LONG_MAX || Z_DVAL_P(tmp_data_copy) < LONG_MIN) { + if (Z_DVAL_P(tmp_data_copy) > PHP_INT_MAX || Z_DVAL_P(tmp_data_copy) < PHP_INT_MIN) { - stmt->send_types_to_server = resend_types_next_time = 1; + stmt->send_types_to_server = *resend_types_next_time = 1; convert_to_string_ex(&tmp_data); } else { - convert_to_long_ex(&tmp_data); + convert_to_int_ex(&tmp_data); } zval_ptr_dtor(&tmp_data_copy); } } } + DBG_RETURN(PASS); + end: + DBG_RETURN(FAIL); + } + /* }}} */ - int1store(*p, stmt->send_types_to_server); - (*p)++; - if (stmt->send_types_to_server) { - if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, stmt->param_count * 2 TSRMLS_CC)) { - SET_OOM_ERROR(*stmt->error_info); - goto end; - } - for (i = 0; i < stmt->param_count; i++) { - short current_type = stmt->param_bind[i].type; - /* our types are not unsigned */ + /* {{{ mysqlnd_stmt_execute_store_types */ + static void + mysqlnd_stmt_execute_store_types(MYSQLND_STMT_DATA * stmt, zval ** copies, zend_uchar ** p) + { - unsigned int i; ++ php_uint_t i; + for (i = 0; i < stmt->param_count; i++) { + short current_type = stmt->param_bind[i].type; + /* our types are not unsigned */ -#if SIZEOF_LONG==8 +#if SIZEOF_ZEND_INT==8 - if (current_type == MYSQL_TYPE_LONG) { - current_type = MYSQL_TYPE_LONGLONG; - } + if (current_type == MYSQL_TYPE_LONG) { + current_type = MYSQL_TYPE_LONGLONG; + } #endif - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) { + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) { + /* + if it doesn't fit in a long send it as a string. + Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX + */ + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) { + const zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv; /* - if it doesn't fit in a long send it as a string. - Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > PHP_INT_MAX + In case of IS_LONG we do nothing, it is ok, in case of string, we just need to set current_type. + The actual transformation has been performed several dozens line above. */ - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_INT) { - zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv; + if (Z_TYPE_P(tmp_data) == IS_STRING) { + current_type = MYSQL_TYPE_VAR_STRING; /* - In case of IS_INT we do nothing, it is ok, in case of string, we just need to set current_type. - The actual transformation has been performed several dozens line above. + don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING + we force convert_to_long_ex in all cases, thus the type will be right in the next switch. + if the type is however not long, then we will do a goto in the next switch. + We want to preserve the original bind type given by the user. Thus, we do these hacks. */ - if (Z_TYPE_P(tmp_data) == IS_STRING) { - current_type = MYSQL_TYPE_VAR_STRING; - /* - don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING - we force convert_to_int_ex in all cases, thus the type will be right in the next switch. - if the type is however not long, then we will do a goto in the next switch. - We want to preserve the original bind type given by the user. Thus, we do these hacks. - */ - } } } - int2store(*p, current_type); - *p+= 2; } + int2store(*p, current_type); + *p+= 2; } - stmt->send_types_to_server = resend_types_next_time; + } + /* }}} */ + + + /* {{{ mysqlnd_stmt_execute_calculate_param_values_size */ + static enum_func_status + mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval *** copies_param, size_t * data_size TSRMLS_DC) + { + unsigned int i; + DBG_ENTER("mysqlnd_stmt_execute_calculate_param_values_size"); - /* 2. Store data */ - /* 2.1 Calculate how much space we need */ for (i = 0; i < stmt->param_count; i++) { + zval ** copies; - unsigned int j; + php_uint_t j; zval *the_var = stmt->param_bind[i].zv; if (!the_var || (stmt->param_bind[i].type != MYSQL_TYPE_LONG_BLOB && Z_TYPE_P(the_var) == IS_NULL)) { @@@ -708,9 -710,9 +710,9 @@@ if (Z_TYPE_P(tmp_data) == IS_STRING) { goto use_string; } - convert_to_long_ex(&tmp_data); + convert_to_int_ex(&tmp_data); } - data_size += 8; + *data_size += 8; break; case MYSQL_TYPE_LONG: { @@@ -718,9 -720,9 +720,9 @@@ if (Z_TYPE_P(tmp_data) == IS_STRING) { goto use_string; } - convert_to_long_ex(&tmp_data); + convert_to_int_ex(&tmp_data); } - data_size += 4; + *data_size += 4; break; case MYSQL_TYPE_LONG_BLOB: if (!(stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED)) { @@@ -745,7 -748,7 +748,7 @@@ use_string the_var = copies[i]; } convert_to_string_ex(&the_var); - data_size += Z_STRSIZE_P(the_var); - *data_size += Z_STRLEN_P(the_var); ++ *data_size += Z_STRSIZE_P(the_var); break; } }
diff --cc ext/mysqlnd/mysqlnd_ps_codec.c index 665d7e2,e08bb26..4b2aaee --- a/ext/mysqlnd/mysqlnd_ps_codec.c +++ b/ext/mysqlnd/mysqlnd_ps_codec.c @@@ -544,56 -561,29 +561,29 @@@ mysqlnd_stmt_execute_check_n_enlarge_bu /* }}} */ - /* {{{ mysqlnd_stmt_execute_store_params */ + /* {{{ mysqlnd_stmt_execute_prepare_param_types */ static enum_func_status - mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar **p, size_t * buf_len TSRMLS_DC) + mysqlnd_stmt_execute_prepare_param_types(MYSQLND_STMT_DATA * stmt, zval *** copies_param, int * resend_types_next_time TSRMLS_DC) { - MYSQLND_STMT_DATA * stmt = s->data; - php_uint_t i = 0; - zend_uchar * provided_buffer = *buf; - size_t data_size = 0; - zval **copies = NULL;/* if there are different types */ - enum_func_status ret = FAIL; - int resend_types_next_time = 0; - size_t null_byte_offset; - - DBG_ENTER("mysqlnd_stmt_execute_store_params"); - - { - php_uint_t null_count = (stmt->param_count + 7) / 8; - if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, null_count TSRMLS_CC)) { - SET_OOM_ERROR(*stmt->error_info); - goto end; - } - /* put `null` bytes */ - null_byte_offset = *p - *buf; - memset(*p, 0, null_count); - *p += null_count; - } - - /* 1. Store type information */ - /* - check if need to send the types even if stmt->send_types_to_server is 0. This is because - if we send "i" (42) then the type will be int and the server will expect int. However, if next - time we try to send > PHP_INT_MAX, the conversion to string will send a string and the server - won't expect it and interpret the value as 0. Thus we need to resend the types, if any such values - occur, and force resend for the next execution. - */ - unsigned int i; ++ php_uint_t i; + DBG_ENTER("mysqlnd_stmt_execute_prepare_param_types"); for (i = 0; i < stmt->param_count; i++) { short current_type = stmt->param_bind[i].type; if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) { + zval ** copies; /* always copy the var, because we do many conversions */ - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG && + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_INT && - PASS != mysqlnd_stmt_copy_it(&copies, stmt->param_bind[i].zv, stmt->param_count, i TSRMLS_CC)) + PASS != mysqlnd_stmt_copy_it(copies_param, stmt->param_bind[i].zv, stmt->param_count, i TSRMLS_CC)) { SET_OOM_ERROR(*stmt->error_info); goto end; } + copies = *copies_param; /* if it doesn't fit in a long send it as a string. - Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX + Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > PHP_INT_MAX */ - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) { + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_INT) { zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv; /* Because converting to double and back to long can lead @@@ -609,69 -599,79 +599,79 @@@ /* if it doesn't fit in a long send it as a string. - Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX + Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > PHP_INT_MAX We do transformation here, which will be used later when sending types. The code later relies on this. */ - if (Z_DVAL_P(tmp_data_copy) > LONG_MAX || Z_DVAL_P(tmp_data_copy) < LONG_MIN) { + if (Z_DVAL_P(tmp_data_copy) > PHP_INT_MAX || Z_DVAL_P(tmp_data_copy) < PHP_INT_MIN) { - stmt->send_types_to_server = resend_types_next_time = 1; + stmt->send_types_to_server = *resend_types_next_time = 1; convert_to_string_ex(&tmp_data); } else { - convert_to_long_ex(&tmp_data); + convert_to_int_ex(&tmp_data); } zval_ptr_dtor(&tmp_data_copy); } } } + DBG_RETURN(PASS); + end: + DBG_RETURN(FAIL); + } + /* }}} */ - int1store(*p, stmt->send_types_to_server); - (*p)++; - if (stmt->send_types_to_server) { - if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, stmt->param_count * 2 TSRMLS_CC)) { - SET_OOM_ERROR(*stmt->error_info); - goto end; - } - for (i = 0; i < stmt->param_count; i++) { - short current_type = stmt->param_bind[i].type; - /* our types are not unsigned */ + /* {{{ mysqlnd_stmt_execute_store_types */ + static void + mysqlnd_stmt_execute_store_types(MYSQLND_STMT_DATA * stmt, zval ** copies, zend_uchar ** p) + { - unsigned int i; ++ php_uint_t i; + for (i = 0; i < stmt->param_count; i++) { + short current_type = stmt->param_bind[i].type; + /* our types are not unsigned */ -#if SIZEOF_LONG==8 +#if SIZEOF_ZEND_INT==8 - if (current_type == MYSQL_TYPE_LONG) { - current_type = MYSQL_TYPE_LONGLONG; - } + if (current_type == MYSQL_TYPE_LONG) { + current_type = MYSQL_TYPE_LONGLONG; + } #endif - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) { + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) { + /* + if it doesn't fit in a long send it as a string. + Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX + */ + if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) { + const zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv; /* - if it doesn't fit in a long send it as a string. - Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > PHP_INT_MAX + In case of IS_LONG we do nothing, it is ok, in case of string, we just need to set current_type. + The actual transformation has been performed several dozens line above. */ - if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_INT) { - zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv; + if (Z_TYPE_P(tmp_data) == IS_STRING) { + current_type = MYSQL_TYPE_VAR_STRING; /* - In case of IS_INT we do nothing, it is ok, in case of string, we just need to set current_type. - The actual transformation has been performed several dozens line above. + don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING + we force convert_to_long_ex in all cases, thus the type will be right in the next switch. + if the type is however not long, then we will do a goto in the next switch. + We want to preserve the original bind type given by the user. Thus, we do these hacks. */ - if (Z_TYPE_P(tmp_data) == IS_STRING) { - current_type = MYSQL_TYPE_VAR_STRING; - /* - don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING - we force convert_to_int_ex in all cases, thus the type will be right in the next switch. - if the type is however not long, then we will do a goto in the next switch. - We want to preserve the original bind type given by the user. Thus, we do these hacks. - */ - } } } - int2store(*p, current_type); - *p+= 2; } + int2store(*p, current_type); + *p+= 2; } - stmt->send_types_to_server = resend_types_next_time; + } + /* }}} */ + + + /* {{{ mysqlnd_stmt_execute_calculate_param_values_size */ + static enum_func_status + mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval *** copies_param, size_t * data_size TSRMLS_DC) + { + unsigned int i; + DBG_ENTER("mysqlnd_stmt_execute_calculate_param_values_size"); - /* 2. Store data */ - /* 2.1 Calculate how much space we need */ for (i = 0; i < stmt->param_count; i++) { + zval ** copies; - unsigned int j; + php_uint_t j; zval *the_var = stmt->param_bind[i].zv; if (!the_var || (stmt->param_bind[i].type != MYSQL_TYPE_LONG_BLOB && Z_TYPE_P(the_var) == IS_NULL)) { @@@ -708,9 -710,9 +710,9 @@@ if (Z_TYPE_P(tmp_data) == IS_STRING) { goto use_string; } - convert_to_long_ex(&tmp_data); + convert_to_int_ex(&tmp_data); } - data_size += 8; + *data_size += 8; break; case MYSQL_TYPE_LONG: { @@@ -718,9 -720,9 +720,9 @@@ if (Z_TYPE_P(tmp_data) == IS_STRING) { goto use_string; } - convert_to_long_ex(&tmp_data); + convert_to_int_ex(&tmp_data); } - data_size += 4; + *data_size += 4; break; case MYSQL_TYPE_LONG_BLOB: if (!(stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED)) { @@@ -745,7 -748,7 +748,7 @@@ use_string the_var = copies[i]; } convert_to_string_ex(&the_var); - data_size += Z_STRSIZE_P(the_var); - *data_size += Z_STRLEN_P(the_var); ++ *data_size += Z_STRSIZE_P(the_var); break; } }