Skip to content

Commit f83e88e

Browse files
committed
Merge branch 'PHP-5.6'
2 parents 90325ba + b2cd56c commit f83e88e

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s TSRMLS_DC)
105105
ret = result->m.store_result_fetch_data(conn, result, result->meta, TRUE TSRMLS_CC);
106106

107107
if (PASS == ret) {
108+
/* Overflow ? */
109+
MYSQLND_RES_BUFFERED * set = result->stored_data;
110+
if (set->row_count) {
111+
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
112+
if (set->row_count * result->meta->field_count * sizeof(zval *) > SIZE_MAX) {
113+
SET_OOM_ERROR(*conn->error_info);
114+
DBG_RETURN(NULL);
115+
}
116+
/* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux) */
117+
set->data = mnd_emalloc((size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
118+
if (!set->data) {
119+
SET_OOM_ERROR(*conn->error_info);
120+
DBG_RETURN(NULL);
121+
}
122+
memset(set->data, 0, (size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
123+
}
124+
/* Position at the first row */
125+
set->data_cursor = set->data;
126+
127+
108128
/* libmysql API docs say it should be so for SELECT statements */
109129
stmt->upsert_status->affected_rows = stmt->result->stored_data->row_count;
110130

ext/mysqlnd/mysqlnd_result.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
11551155
*/
11561156
}
11571157
/* Overflow ? */
1158+
#if 0
11581159
if (set->row_count) {
11591160
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
11601161
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
11711172
}
11721173
memset(set->data, 0, (size_t)(set->row_count * meta->field_count * sizeof(zval *)));
11731174
}
1174-
1175+
#endif
11751176
MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn->stats,
11761177
binary_protocol? STAT_ROWS_BUFFERED_FROM_CLIENT_PS:
11771178
STAT_ROWS_BUFFERED_FROM_CLIENT_NORMAL,
@@ -1203,9 +1204,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
12031204
if (ret == FAIL) {
12041205
COPY_CLIENT_ERROR(set->error_info, row_packet->error_info);
12051206
} else {
1206-
/* Position at the first row */
1207-
set->data_cursor = set->data;
1208-
12091207
/* libmysql's documentation says it should be so for SELECT statements */
12101208
conn->upsert_status->affected_rows = set->row_count;
12111209
}
@@ -1255,7 +1253,27 @@ MYSQLND_METHOD(mysqlnd_res, store_result)(MYSQLND_RES * result,
12551253
SET_OOM_ERROR(*conn->error_info);
12561254
}
12571255
DBG_RETURN(NULL);
1256+
} else {
1257+
/* Overflow ? */
1258+
MYSQLND_RES_BUFFERED * set = result->stored_data;
1259+
if (set->row_count) {
1260+
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
1261+
if (set->row_count * result->meta->field_count * sizeof(zval *) > SIZE_MAX) {
1262+
SET_OOM_ERROR(*conn->error_info);
1263+
DBG_RETURN(NULL);
1264+
}
1265+
/* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux) */
1266+
set->data = mnd_emalloc((size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
1267+
if (!set->data) {
1268+
SET_OOM_ERROR(*conn->error_info);
1269+
DBG_RETURN(NULL);
1270+
}
1271+
memset(set->data, 0, (size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
1272+
}
1273+
/* Position at the first row */
1274+
set->data_cursor = set->data;
12581275
}
1276+
12591277
/* libmysql's documentation says it should be so for SELECT statements */
12601278
conn->upsert_status->affected_rows = result->stored_data->row_count;
12611279

0 commit comments

Comments
 (0)