From: Andrey Hristov Date: Mon, 17 Feb 2014 16:37:08 +0000 (+0200) Subject: Move code out, that handles the actual structure to be used for the decoded X-Git-Tag: php-5.6.0alpha3~1^2~68 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2cd56c3cb9e752e3d0e4accb99d0f2e1ac71632;p=php Move code out, that handles the actual structure to be used for the decoded data. Will make it easier to add different structures --- diff --git a/ext/mysqlnd/mysqlnd_ps.c b/ext/mysqlnd/mysqlnd_ps.c index 8096cbbbd9..fa2abc71d7 100644 --- a/ext/mysqlnd/mysqlnd_ps.c +++ b/ext/mysqlnd/mysqlnd_ps.c @@ -104,6 +104,26 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s TSRMLS_DC) ret = result->m.store_result_fetch_data(conn, result, result->meta, TRUE TSRMLS_CC); if (PASS == ret) { + /* Overflow ? */ + MYSQLND_RES_BUFFERED * set = result->stored_data; + if (set->row_count) { + /* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */ + if (set->row_count * result->meta->field_count * sizeof(zval *) > SIZE_MAX) { + SET_OOM_ERROR(*conn->error_info); + DBG_RETURN(NULL); + } + /* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux) */ + set->data = mnd_emalloc((size_t)(set->row_count * result->meta->field_count * sizeof(zval *))); + if (!set->data) { + SET_OOM_ERROR(*conn->error_info); + DBG_RETURN(NULL); + } + memset(set->data, 0, (size_t)(set->row_count * result->meta->field_count * sizeof(zval *))); + } + /* Position at the first row */ + set->data_cursor = set->data; + + /* libmysql API docs say it should be so for SELECT statements */ stmt->upsert_status->affected_rows = stmt->result->stored_data->row_count; diff --git a/ext/mysqlnd/mysqlnd_result.c b/ext/mysqlnd/mysqlnd_result.c index fbf8ea031c..944999b79c 100644 --- a/ext/mysqlnd/mysqlnd_result.c +++ b/ext/mysqlnd/mysqlnd_result.c @@ -1155,6 +1155,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c */ } /* Overflow ? */ +#if 0 if (set->row_count) { /* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */ if (set->row_count * meta->field_count * sizeof(zval *) > SIZE_MAX) { @@ -1171,7 +1172,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c } memset(set->data, 0, (size_t)(set->row_count * meta->field_count * sizeof(zval *))); } - +#endif MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn->stats, binary_protocol? STAT_ROWS_BUFFERED_FROM_CLIENT_PS: STAT_ROWS_BUFFERED_FROM_CLIENT_NORMAL, @@ -1203,9 +1204,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c if (ret == FAIL) { COPY_CLIENT_ERROR(set->error_info, row_packet->error_info); } else { - /* Position at the first row */ - set->data_cursor = set->data; - /* libmysql's documentation says it should be so for SELECT statements */ conn->upsert_status->affected_rows = set->row_count; } @@ -1255,7 +1253,27 @@ MYSQLND_METHOD(mysqlnd_res, store_result)(MYSQLND_RES * result, SET_OOM_ERROR(*conn->error_info); } DBG_RETURN(NULL); + } else { + /* Overflow ? */ + MYSQLND_RES_BUFFERED * set = result->stored_data; + if (set->row_count) { + /* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */ + if (set->row_count * result->meta->field_count * sizeof(zval *) > SIZE_MAX) { + SET_OOM_ERROR(*conn->error_info); + DBG_RETURN(NULL); + } + /* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux) */ + set->data = mnd_emalloc((size_t)(set->row_count * result->meta->field_count * sizeof(zval *))); + if (!set->data) { + SET_OOM_ERROR(*conn->error_info); + DBG_RETURN(NULL); + } + memset(set->data, 0, (size_t)(set->row_count * result->meta->field_count * sizeof(zval *))); + } + /* Position at the first row */ + set->data_cursor = set->data; } + /* libmysql's documentation says it should be so for SELECT statements */ conn->upsert_status->affected_rows = result->stored_data->row_count;