--- embedaddon/php/ext/mysqlnd/mysqlnd.c 2012/05/29 12:34:41 1.1.1.2 +++ embedaddon/php/ext/mysqlnd/mysqlnd.c 2013/10/14 08:02:25 1.1.1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 2006-2012 The PHP Group | + | Copyright (c) 2006-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mysqlnd.c,v 1.1.1.2 2012/05/29 12:34:41 misho Exp $ */ +/* $Id: mysqlnd.c,v 1.1.1.4 2013/10/14 08:02:25 misho Exp $ */ #include "php.h" #include "mysqlnd.h" #include "mysqlnd_wireprotocol.h" @@ -764,9 +764,18 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CON conn->server_version = mnd_pestrdup(greet_packet->server_version, conn->persistent); conn->greet_charset = mysqlnd_find_charset_nr(greet_packet->charset_no); + if (!conn->greet_charset) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet->charset_no); + SET_CLIENT_ERROR(*conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, + "Server sent charset unknown to the client. Please, report to the developers"); + goto err; + } /* we allow load data local infile by default */ mysql_flags |= MYSQLND_CAPABILITIES; + mysql_flags |= conn->options->flags; /* use the flags from set_client_option() */ + if (db) { mysql_flags |= CLIENT_CONNECT_WITH_DB; } @@ -975,8 +984,8 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn_h } DBG_RETURN(ret); } +/* }}} */ - /* {{{ mysqlnd_connect */ PHPAPI MYSQLND * mysqlnd_connect(MYSQLND * conn_handle, const char * host, const char * user, @@ -1052,7 +1061,7 @@ static enum_func_status MYSQLND_METHOD(mysqlnd_conn_data, send_query)(MYSQLND_CONN_DATA * conn, const char * query, unsigned int query_len TSRMLS_DC) { size_t this_func = STRUCT_OFFSET(struct st_mysqlnd_conn_data_methods, send_query); - enum_func_status ret; + enum_func_status ret = FAIL; DBG_ENTER("mysqlnd_conn_data::send_query"); DBG_INF_FMT("conn=%llu query=%s", conn->thread_id, query); @@ -1133,6 +1142,7 @@ MYSQLND ** mysqlnd_stream_array_check_for_readiness(MY static int mysqlnd_stream_array_to_fd_set(MYSQLND ** conn_array, fd_set * fds, php_socket_t * max_fd TSRMLS_DC) { php_socket_t this_fd; + php_stream *stream = NULL; int cnt = 0; MYSQLND **p = conn_array; @@ -1142,7 +1152,8 @@ static int mysqlnd_stream_array_to_fd_set(MYSQLND ** c * when casting. It is only used here so that the buffered data warning * is not displayed. * */ - if (SUCCESS == php_stream_cast((*p)->data->net->stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, + stream = (*p)->data->net->stream; + if (stream != NULL && SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd >= 0) { PHP_SAFE_FD_SET(this_fd, fds); @@ -1160,6 +1171,7 @@ static int mysqlnd_stream_array_to_fd_set(MYSQLND ** c static int mysqlnd_stream_array_from_fd_set(MYSQLND ** conn_array, fd_set * fds TSRMLS_DC) { php_socket_t this_fd; + php_stream *stream = NULL; int ret = 0; zend_bool disproportion = FALSE; @@ -1167,7 +1179,8 @@ static int mysqlnd_stream_array_from_fd_set(MYSQLND ** MYSQLND **fwd = conn_array, **bckwd = conn_array; while (*fwd) { - if (SUCCESS == php_stream_cast((*fwd)->data->net->stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, + stream = (*fwd)->data->net->stream; + if (stream != NULL && SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd >= 0) { if (PHP_SAFE_FD_ISSET(this_fd, fds)) { if (disproportion) { @@ -1328,7 +1341,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, list_fields)(MYSQLND } if (FAIL == result->m.read_result_metadata(result, conn TSRMLS_CC)) { - DBG_ERR("Error ocurred while reading metadata"); + DBG_ERR("Error occurred while reading metadata"); result->m.free_result(result, TRUE TSRMLS_CC); result = NULL; break; @@ -1459,7 +1472,7 @@ static ulong MYSQLND_METHOD(mysqlnd_conn_data, escape_string)(MYSQLND_CONN_DATA * const conn, char * newstr, const char * escapestr, size_t escapestr_len TSRMLS_DC) { size_t this_func = STRUCT_OFFSET(struct st_mysqlnd_conn_data_methods, escape_string); - ulong ret; + ulong ret = FAIL; DBG_ENTER("mysqlnd_conn_data::escape_string"); DBG_INF_FMT("conn=%llu", conn->thread_id); @@ -2177,7 +2190,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, change_user)(MYSQLND } memcpy(conn->auth_plugin_data, plugin_data, plugin_data_len); - DBG_INF_FMT("salt=[%*s]", plugin_data_len - 1, plugin_data); + DBG_INF_FMT("salt=[%*.s]", plugin_data_len - 1, plugin_data); /* The data should be allocated with malloc() */ scrambled_data = @@ -2277,7 +2290,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(M break; #endif case MYSQL_OPT_LOCAL_INFILE: - if (!value || (*(unsigned int*) value) ? 1 : 0) { + if (value && (*(unsigned int*) value) ? 1 : 0) { conn->options->flags |= CLIENT_LOCAL_FILES; } else { conn->options->flags &= ~CLIENT_LOCAL_FILES; @@ -2312,7 +2325,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(M break; case MYSQL_SET_CHARSET_NAME: { - char * new_charset_name = mnd_pestrdup(value, conn->persistent); + char * new_charset_name; + if (!mysqlnd_find_charset_name(value)) { + SET_CLIENT_ERROR(*conn->error_info, CR_CANT_FIND_CHARSET, UNKNOWN_SQLSTATE, "Unknown character set"); + ret = FAIL; + break; + } + + new_charset_name = mnd_pestrdup(value, conn->persistent); if (!new_charset_name) { goto oom; } @@ -2361,6 +2381,13 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(M DBG_INF_FMT("auth_protocol=%s", conn->options->auth_protocol); break; } + case MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS: + if (value && (*(unsigned int*) value) ? 1 : 0) { + conn->options->flags |= CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS; + } else { + conn->options->flags &= ~CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS; + } + break; #ifdef WHEN_SUPPORTED_BY_MYSQLI case MYSQL_SHARED_MEMORY_BASE_NAME: case MYSQL_OPT_USE_RESULT: