svn: /php/php-src/ branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c trunk/ext/mysqlnd/mysqlnd_result.c
| From: | Andrey Hristov | Date: | Tue, 05 Oct 2010 16:54:14 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c trunk/ext/mysqlnd/mysqlnd_result.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-63649@lists.php.net to get a copy of this message | ||
andrey Tue, 05 Oct 2010 16:54:14 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=304113
Log:
Fix compiler warnings - on 32bit size_t is smaller than uint64_t, although
we will never hit this the compiler should be happy.
Changed paths:
U php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c
U php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c
Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c 2010-10-05 16:27:49 UTC (rev 304112)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c 2010-10-05 16:54:14 UTC (rev 304113)
@@ -1147,7 +1147,7 @@
goto end;
}
if (free_rows) {
- set->row_buffers = mnd_pemalloc(free_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *), to_cache);
+ set->row_buffers = mnd_pemalloc((size_t)(free_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)),
to_cache);
if (!set->row_buffers) {
SET_OOM_ERROR(conn->error_info);
ret = FAIL;
@@ -1181,8 +1181,15 @@
uint64_t total_allocated_rows = free_rows = next_extend = next_extend * 11 / 10; /* extend with
10% */
MYSQLND_MEMORY_POOL_CHUNK ** new_row_buffers;
total_allocated_rows += 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 (total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *) > SIZE_MAX) {
+ SET_OOM_ERROR(conn->error_info);
+ ret = FAIL;
+ goto end;
+ }
new_row_buffers = mnd_perealloc(set->row_buffers,
- total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *),
+ (size_t)(total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)),
set->persistent);
if (!new_row_buffers) {
SET_OOM_ERROR(conn->error_info);
@@ -1209,8 +1216,14 @@
}
/* Overflow ? */
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) {
+ SET_OOM_ERROR(conn->error_info);
+ ret = FAIL;
+ goto end;
+ }
/* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch
revision 135036] (SUSE Linux) */
- set->data = mnd_pemalloc(set->row_count * meta->field_count * sizeof(zval *), to_cache);
+ set->data = mnd_pemalloc((size_t)(set->row_count * meta->field_count * sizeof(zval *)),
to_cache);
if (!set->data) {
SET_OOM_ERROR(conn->error_info);
ret = FAIL;
@@ -1231,8 +1244,14 @@
}
/* save some memory */
if (free_rows) {
+ /* 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 * sizeof(MYSQLND_MEMORY_POOL_CHUNK *) > SIZE_MAX) {
+ SET_OOM_ERROR(conn->error_info);
+ ret = FAIL;
+ goto end;
+ }
set->row_buffers = mnd_perealloc(set->row_buffers,
- set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *),
+ (size_t) (set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)),
set->persistent);
}
@@ -1593,7 +1612,8 @@
DBG_VOID_RETURN;
}
- mysqlnd_array_init(return_value, (unsigned int) set? set->row_count : 4); /* 4 is a magic value
*/
+ /* 4 is a magic value. The cast is safe, if larger then the array will be later extended - no big
deal :) */
+ mysqlnd_array_init(return_value, (unsigned int) set? (uint) set->row_count : 4);
do {
MAKE_STD_ZVAL(row);
Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c 2010-10-05 16:27:49 UTC (rev 304112)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c 2010-10-05 16:54:14 UTC (rev 304113)
@@ -1147,7 +1147,7 @@
goto end;
}
if (free_rows) {
- set->row_buffers = mnd_pemalloc(free_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *), to_cache);
+ set->row_buffers = mnd_pemalloc((size_t)(free_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)),
to_cache);
if (!set->row_buffers) {
SET_OOM_ERROR(conn->error_info);
ret = FAIL;
@@ -1181,8 +1181,15 @@
uint64_t total_allocated_rows = free_rows = next_extend = next_extend * 11 / 10; /* extend with
10% */
MYSQLND_MEMORY_POOL_CHUNK ** new_row_buffers;
total_allocated_rows += 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 (total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *) > SIZE_MAX) {
+ SET_OOM_ERROR(conn->error_info);
+ ret = FAIL;
+ goto end;
+ }
new_row_buffers = mnd_perealloc(set->row_buffers,
- total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *),
+ (size_t)(total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)),
set->persistent);
if (!new_row_buffers) {
SET_OOM_ERROR(conn->error_info);
@@ -1209,8 +1216,14 @@
}
/* Overflow ? */
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) {
+ SET_OOM_ERROR(conn->error_info);
+ ret = FAIL;
+ goto end;
+ }
/* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch
revision 135036] (SUSE Linux) */
- set->data = mnd_pemalloc(set->row_count * meta->field_count * sizeof(zval *), to_cache);
+ set->data = mnd_pemalloc((size_t)(set->row_count * meta->field_count * sizeof(zval *)),
to_cache);
if (!set->data) {
SET_OOM_ERROR(conn->error_info);
ret = FAIL;
@@ -1231,8 +1244,14 @@
}
/* save some memory */
if (free_rows) {
+ /* 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 * sizeof(MYSQLND_MEMORY_POOL_CHUNK *) > SIZE_MAX) {
+ SET_OOM_ERROR(conn->error_info);
+ ret = FAIL;
+ goto end;
+ }
set->row_buffers = mnd_perealloc(set->row_buffers,
- set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *),
+ (size_t) (set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)),
set->persistent);
}
@@ -1590,7 +1609,8 @@
DBG_VOID_RETURN;
}
- mysqlnd_array_init(return_value, (unsigned int) set? set->row_count : 4); /* 4 is a magic value
*/
+ /* 4 is a magic value. The cast is safe, if larger then the array will be later extended - no big
deal :) */
+ mysqlnd_array_init(return_value, (unsigned int) set? (uint) set->row_count : 4);
do {
MAKE_STD_ZVAL(row);