Skip to content

Commit b2cd56c

Browse files
committed
Move code out, that handles the actual structure to be used for the decoded
data. Will make it easier to add different structures
1 parent 0bc96ef commit b2cd56c

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

ext/mysqlnd/mysqlnd_ps.c

+20
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s TSRMLS_DC)
104104
ret = result->m.store_result_fetch_data(conn, result, result->meta, TRUE TSRMLS_CC);
105105

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

ext/mysqlnd/mysqlnd_result.c

+22-4
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)