Merge lp:~wiml/libdrizzle/integer-sizes into lp:libdrizzle

Proposed by Wim Lewis
Status: Merged
Approved by: Andrew Hutchings
Approved revision: 121
Merged at revision: 109
Proposed branch: lp:~wiml/libdrizzle/integer-sizes
Merge into: lp:libdrizzle
Diff against target: 618 lines (+134/-80)
14 files modified
libdrizzle-5.1/constants.h (+15/-21)
libdrizzle-5.1/field_client.h (+17/-2)
libdrizzle/binlog.cc (+5/-5)
libdrizzle/conn.cc (+6/-0)
libdrizzle/field.cc (+36/-18)
libdrizzle/handshake.cc (+2/-2)
libdrizzle/pack.cc (+19/-7)
libdrizzle/pack.h (+2/-1)
libdrizzle/result.cc (+10/-8)
libdrizzle/result.h (+6/-6)
libdrizzle/statement.cc (+1/-1)
libdrizzle/statement_param.cc (+8/-2)
libdrizzle/structs.h (+6/-6)
tests/unit/statement.c (+1/-1)
To merge this branch: bzr merge lp:~wiml/libdrizzle/integer-sizes
Reviewer Review Type Date Requested Status
Andrew Hutchings Approve
Review via email: mp+152963@code.launchpad.net

Commit message

Adjusting the sizes of integer variables to avoid truncation or overflow; also fixed some errors reading large responses or prepared-statement responses.

Description of the change

This is the result of examining libdrizzle for integer truncation and overflow problems. A few other small bugs were found and fixed along the way--- see the individual commit messages for these.

To post a comment you must log in.
Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

Very nice catches in there, most of them my silly mistakes, especially around prepared stmt :)

Worst case this slightly breaks API on the drizzle_field functions, but only for 32bit so I'm not so concerned.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libdrizzle-5.1/constants.h'
--- libdrizzle-5.1/constants.h 2013-01-28 01:04:53 +0000
+++ libdrizzle-5.1/constants.h 2013-03-12 16:48:27 +0000
@@ -604,27 +604,21 @@
604 */604 */
605605
606/* Protocol unpacking macros. */606/* Protocol unpacking macros. */
607#define drizzle_get_byte2(__buffer) \607#define drizzle_get_byte2(__buffer) \
608 (uint16_t)((__buffer)[0] | \608 ((((uint8_t *)__buffer)[0]) | \
609 ((__buffer)[1] << 8))609 ((uint16_t)(((uint8_t *)__buffer)[1]) << 8))
610#define drizzle_get_byte3(__buffer) \610#define drizzle_get_byte3(__buffer) \
611 (uint32_t)((__buffer)[0] | \611 (((uint8_t *)__buffer)[0] | \
612 ((__buffer)[1] << 8) | \612 ((uint32_t)(((uint8_t *)__buffer)[1]) << 8) | \
613 ((__buffer)[2] << 16))613 ((uint32_t)(((uint8_t *)__buffer)[2]) << 16))
614#define drizzle_get_byte4(__buffer) \614#define drizzle_get_byte4(__buffer) \
615 (uint32_t)((__buffer)[0] | \615 (((uint8_t *)__buffer)[0] | \
616 ((__buffer)[1] << 8) | \616 ((uint32_t)(((uint8_t *)__buffer)[1]) << 8) | \
617 ((__buffer)[2] << 16) | \617 ((uint32_t)(((uint8_t *)__buffer)[2]) << 16) | \
618 ((__buffer)[3] << 24))618 ((uint32_t)(((uint8_t *)__buffer)[3]) << 24))
619#define drizzle_get_byte8(__buffer) \619#define drizzle_get_byte8(__buffer) \
620 ((uint64_t)(__buffer)[0] | \620 (drizzle_get_byte4(__buffer) | \
621 ((uint64_t)(__buffer)[1] << 8) | \621 ((uint64_t)drizzle_get_byte4(((uint8_t *)__buffer)+4) << 32))
622 ((uint64_t)(__buffer)[2] << 16) | \
623 ((uint64_t)(__buffer)[3] << 24) | \
624 ((uint64_t)(__buffer)[4] << 32) | \
625 ((uint64_t)(__buffer)[5] << 40) | \
626 ((uint64_t)(__buffer)[6] << 48) | \
627 ((uint64_t)(__buffer)[7] << 56))
628622
629/* Protocol packing macros. */623/* Protocol packing macros. */
630#define drizzle_set_byte2(__buffer, __int) do { \624#define drizzle_set_byte2(__buffer, __int) do { \
631625
=== modified file 'libdrizzle-5.1/field_client.h'
--- libdrizzle-5.1/field_client.h 2013-01-27 11:55:48 +0000
+++ libdrizzle-5.1/field_client.h 2013-03-12 16:48:27 +0000
@@ -60,14 +60,29 @@
60 * Read field for unbuffered result, possibly in parts. This is especially60 * Read field for unbuffered result, possibly in parts. This is especially
61 * useful for blob streaming, since the client does not need to buffer the61 * useful for blob streaming, since the client does not need to buffer the
62 * entire blob.62 * entire blob.
63 *
64 * The return value is a pointer into a buffer internal to \a result and should
65 * not be freed. It is valid only until the next call to a drizzle function for this
66 * connection.
67 *
68 * @returns A pointer to \a size bytes of field data.
69 * @param[in,out] result The result handle for the response being read.
70 * @param[out] offset The offset within the field of the data that was read.
71 * @param[out] size The number of bytes returned.
72 * @param[out] total The total size of the field being read.
73 * @param[out] ret_ptr DRIZZLE_RETURN_*
74 *
63 */75 */
64DRIZZLE_API76DRIZZLE_API
65drizzle_field_t drizzle_field_read(drizzle_result_st *result, size_t *offset,77drizzle_field_t drizzle_field_read(drizzle_result_st *result, uint64_t *offset,
66 size_t *size, size_t *total,78 size_t *size, uint64_t *total,
67 drizzle_return_t *ret_ptr);79 drizzle_return_t *ret_ptr);
6880
69/**81/**
70 * Buffer one field.82 * Buffer one field.
83 *
84 * The return value is a newly allocated buffer and must be freed using drizzle_field_free
85 * when no longer needed.
71 */86 */
72DRIZZLE_API87DRIZZLE_API
73drizzle_field_t drizzle_field_buffer(drizzle_result_st *result, size_t *total,88drizzle_field_t drizzle_field_buffer(drizzle_result_st *result, size_t *total,
7489
=== modified file 'libdrizzle/binlog.cc'
--- libdrizzle/binlog.cc 2013-01-28 01:04:53 +0000
+++ libdrizzle/binlog.cc 2013-03-12 16:48:27 +0000
@@ -289,10 +289,10 @@
289 con->packet_size-= 9;289 con->packet_size-= 9;
290290
291 snprintf(con->last_error, DRIZZLE_MAX_ERROR_SIZE, "%.*s",291 snprintf(con->last_error, DRIZZLE_MAX_ERROR_SIZE, "%.*s",
292 (int32_t)con->packet_size, con->buffer_ptr);292 (int)con->packet_size, con->buffer_ptr);
293 con->last_error[DRIZZLE_MAX_ERROR_SIZE-1]= 0;293 con->last_error[DRIZZLE_MAX_ERROR_SIZE-1]= 0;
294 snprintf(con->result->info, DRIZZLE_MAX_INFO_SIZE, "%.*s",294 snprintf(con->result->info, DRIZZLE_MAX_INFO_SIZE, "%.*s",
295 (int32_t)con->packet_size, con->buffer_ptr);295 (int)con->packet_size, con->buffer_ptr);
296 con->result->info[DRIZZLE_MAX_INFO_SIZE-1]= 0;296 con->result->info[DRIZZLE_MAX_INFO_SIZE-1]= 0;
297 con->buffer_ptr+= con->packet_size;297 con->buffer_ptr+= con->packet_size;
298 con->buffer_size-= con->packet_size;298 con->buffer_size-= con->packet_size;
@@ -315,7 +315,7 @@
315 if (con->packet_size != binlog_event->length)315 if (con->packet_size != binlog_event->length)
316 {316 {
317 drizzle_set_error(con, "drizzle_state_binlog_read",317 drizzle_set_error(con, "drizzle_state_binlog_read",
318 "packet size error:%zu:%zu", con->packet_size, binlog_event->length);318 "packet size error:%"PRIu32":%"PRIu32, con->packet_size, binlog_event->length);
319 con->binlog->error_fn(DRIZZLE_RETURN_UNEXPECTED_DATA, con, con->binlog->binlog_context);319 con->binlog->error_fn(DRIZZLE_RETURN_UNEXPECTED_DATA, con, con->binlog->binlog_context);
320 return DRIZZLE_RETURN_UNEXPECTED_DATA;320 return DRIZZLE_RETURN_UNEXPECTED_DATA;
321 }321 }
@@ -370,10 +370,10 @@
370 memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);370 memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);
371 if (con->binlog->verify_checksums)371 if (con->binlog->verify_checksums)
372 {372 {
373 event_crc= crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));373 event_crc= (uint32_t)crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));
374 if (event_crc != binlog_event->checksum)374 if (event_crc != binlog_event->checksum)
375 {375 {
376 drizzle_set_error(con, __func__, "CRC doesn't match: 0x%lX, 0x%lX", event_crc, binlog_event->checksum);376 drizzle_set_error(con, __func__, "CRC doesn't match: 0x%"PRIX32", 0x%"PRIX32, event_crc, binlog_event->checksum);
377 con->binlog->error_fn(DRIZZLE_RETURN_BINLOG_CRC, con, con->binlog->binlog_context);377 con->binlog->error_fn(DRIZZLE_RETURN_BINLOG_CRC, con, con->binlog->binlog_context);
378 return DRIZZLE_RETURN_BINLOG_CRC;378 return DRIZZLE_RETURN_BINLOG_CRC;
379 }379 }
380380
=== modified file 'libdrizzle/conn.cc'
--- libdrizzle/conn.cc 2013-01-27 11:55:48 +0000
+++ libdrizzle/conn.cc 2013-03-12 16:48:27 +0000
@@ -724,6 +724,12 @@
724{724{
725 drizzle_result_st *result;725 drizzle_result_st *result;
726 drizzle_return_t ret;726 drizzle_return_t ret;
727
728 if (db == NULL)
729 {
730 return DRIZZLE_RETURN_INVALID_ARGUMENT;
731 }
732
727 drizzle_set_db(con, db);733 drizzle_set_db(con, db);
728 result= drizzle_command_write(con, NULL, DRIZZLE_COMMAND_INIT_DB,734 result= drizzle_command_write(con, NULL, DRIZZLE_COMMAND_INIT_DB,
729 db, strlen(db), strlen(db), &ret);735 db, strlen(db), strlen(db), &ret);
730736
=== modified file 'libdrizzle/field.cc'
--- libdrizzle/field.cc 2013-01-27 11:55:48 +0000
+++ libdrizzle/field.cc 2013-03-12 16:48:27 +0000
@@ -48,8 +48,8 @@
48 * Client definitions48 * Client definitions
49 */49 */
5050
51drizzle_field_t drizzle_field_read(drizzle_result_st *result, size_t *offset,51drizzle_field_t drizzle_field_read(drizzle_result_st *result, uint64_t *offset,
52 size_t *size, size_t *total,52 size_t *size, uint64_t *total,
53 drizzle_return_t *ret_ptr)53 drizzle_return_t *ret_ptr)
54{54{
55 drizzle_return_t unused_ret;55 drizzle_return_t unused_ret;
@@ -115,8 +115,9 @@
115drizzle_field_t drizzle_field_buffer(drizzle_result_st *result, size_t *total,115drizzle_field_t drizzle_field_buffer(drizzle_result_st *result, size_t *total,
116 drizzle_return_t *ret_ptr)116 drizzle_return_t *ret_ptr)
117{117{
118 size_t offset= 0;118 uint64_t offset= 0;
119 size_t size= 0;119 size_t size= 0;
120 uint64_t wire_size;
120121
121 drizzle_return_t unused_ret;122 drizzle_return_t unused_ret;
122 if (ret_ptr == NULL)123 if (ret_ptr == NULL)
@@ -130,7 +131,7 @@
130 return 0;131 return 0;
131 }132 }
132133
133 drizzle_field_t field= drizzle_field_read(result, &offset, &size, total, ret_ptr);134 drizzle_field_t field= drizzle_field_read(result, &offset, &size, &wire_size, ret_ptr);
134135
135 if (*ret_ptr != DRIZZLE_RETURN_OK)136 if (*ret_ptr != DRIZZLE_RETURN_OK)
136 {137 {
@@ -143,6 +144,14 @@
143 return NULL;144 return NULL;
144 }145 }
145146
147 if ((SIZE_MAX < UINT64_MAX) && (wire_size >= SIZE_MAX))
148 {
149 drizzle_set_error(result->con, __func__, "Field is larger than memory.");
150 *ret_ptr= DRIZZLE_RETURN_MEMORY;
151 return NULL;
152 }
153 *total = (size_t)wire_size;
154
146 if (result->field_buffer == NULL)155 if (result->field_buffer == NULL)
147 {156 {
148 result->field_buffer= new (std::nothrow) char[(*total) + 1];157 result->field_buffer= new (std::nothrow) char[(*total) + 1];
@@ -158,12 +167,13 @@
158167
159 while ((offset + size) != (*total))168 while ((offset + size) != (*total))
160 {169 {
161 field= drizzle_field_read(result, &offset, &size, total, ret_ptr);170 field= drizzle_field_read(result, &offset, &size, &wire_size, ret_ptr);
162 if (*ret_ptr != DRIZZLE_RETURN_OK)171 if (*ret_ptr != DRIZZLE_RETURN_OK)
163 {172 {
164 return NULL;173 return NULL;
165 }174 }
166175 assert(wire_size == (uint64_t)*total);
176
167 memcpy(result->field_buffer + offset, field, size);177 memcpy(result->field_buffer + offset, field, size);
168 }178 }
169179
@@ -207,7 +217,7 @@
207 con->result->field_size= 0;217 con->result->field_size= 0;
208218
209 drizzle_return_t ret;219 drizzle_return_t ret;
210 con->result->field_total= (size_t)drizzle_unpack_length(con, &ret);220 con->result->field_total= drizzle_unpack_length(con, &ret);
211 if (ret == DRIZZLE_RETURN_NULL_SIZE)221 if (ret == DRIZZLE_RETURN_NULL_SIZE)
212 {222 {
213 con->result->field= NULL;223 con->result->field= NULL;
@@ -227,35 +237,43 @@
227 }237 }
228238
229 drizzle_log_debug(con,239 drizzle_log_debug(con,
230 "field_offset= %zu, field_size= %zu, field_total= %zu",240 "field_offset= %"PRIu64", field_size= %zu, field_total= %"PRIu64,
231 con->result->field_offset, con->result->field_size,241 con->result->field_offset, con->result->field_size,
232 con->result->field_total);242 con->result->field_total);
233243
234 if ((size_t)(con->buffer_size) >= con->result->field_total)244 uint32_t available_data = (con->buffer_size < con->packet_size)? (uint32_t)con->buffer_size : con->packet_size;
245 /* packet_size fits in uint32, so available_data fits in uint32 */
246
247 if (available_data >= con->result->field_total)
235 {248 {
236 con->result->field_size= con->result->field_total;249 /* narrowing cast is safe because field_total<packet_size and packet_size is uint32 */
250 con->result->field_size= (uint32_t)con->result->field_total;
237 }251 }
238 else252 else
239 {253 {
240 con->result->field_size= con->buffer_size;254 con->result->field_size= available_data;
241 }255 }
242 }256 }
243 else257 else
244 {258 {
245 if ((con->result->field_offset + con->buffer_size) >=259 uint32_t available_data = (con->buffer_size < con->packet_size)? (uint32_t)con->buffer_size : con->packet_size;
246 con->result->field_total)260 /* packet_size fits in uint32, so available_data fits in uint32 */
261
262 uint64_t field_remaining = con->result->field_total - con->result->field_offset;
263
264 if (field_remaining <= available_data)
247 {265 {
248 con->result->field_size= (con->result->field_total -266 /* narrowing cast is safe because field_remaining<=packet_size and packet_size is uint32 */
249 con->result->field_offset);267 con->result->field_size= (uint32_t)field_remaining;
250 }268 }
251 else269 else
252 {270 {
253 con->result->field_size= con->buffer_size;271 con->result->field_size= available_data;
254 }272 }
255 }273 }
256274
257 /* This is a special case when a row is larger than the packet size. */275 /* This is a special case when a row is larger than the packet size. */
258 if (con->result->field_size > (size_t)con->packet_size)276 if (con->result->field_size > con->packet_size)
259 {277 {
260 con->result->field_size= con->packet_size;278 con->result->field_size= con->packet_size;
261279
@@ -277,7 +295,7 @@
277 con->packet_size-= con->result->field_size;295 con->packet_size-= con->result->field_size;
278296
279 drizzle_log_debug(con,297 drizzle_log_debug(con,
280 "field_offset= %zu, field_size= %zu, field_total= %zu",298 "field_offset= %"PRIu64", field_size= %zu, field_total= %"PRIu64,
281 con->result->field_offset, con->result->field_size,299 con->result->field_offset, con->result->field_size,
282 con->result->field_total);300 con->result->field_total);
283301
284302
=== modified file 'libdrizzle/handshake.cc'
--- libdrizzle/handshake.cc 2013-01-27 11:55:48 +0000
+++ libdrizzle/handshake.cc 2013-03-12 16:48:27 +0000
@@ -83,7 +83,7 @@
83drizzle_return_t drizzle_state_handshake_server_read(drizzle_st *con)83drizzle_return_t drizzle_state_handshake_server_read(drizzle_st *con)
84{84{
85 unsigned char *ptr;85 unsigned char *ptr;
86 int extra_length;86 ptrdiff_t extra_length;
87 unsigned char* packet_end;87 unsigned char* packet_end;
8888
89 if (con == NULL)89 if (con == NULL)
@@ -117,7 +117,7 @@
117 if (con->protocol_version == 255)117 if (con->protocol_version == 255)
118 {118 {
119 drizzle_set_error(con, "drizzle_state_handshake_server_read",119 drizzle_set_error(con, "drizzle_state_handshake_server_read",
120 "%.*s", (int32_t)con->packet_size - 3,120 "%.*s", (int)con->packet_size - 3,
121 con->buffer_ptr + 2);121 con->buffer_ptr + 2);
122 return DRIZZLE_RETURN_AUTH_FAILED;122 return DRIZZLE_RETURN_AUTH_FAILED;
123 }123 }
124124
=== modified file 'libdrizzle/pack.cc'
--- libdrizzle/pack.cc 2013-01-27 11:55:48 +0000
+++ libdrizzle/pack.cc 2013-03-12 16:48:27 +0000
@@ -165,12 +165,12 @@
165 return NULL;165 return NULL;
166 }166 }
167167
168 uint64_t size= strlen(string);168 size_t size= strlen(string);
169169
170 ptr= drizzle_pack_length(size, ptr);170 ptr= drizzle_pack_length(size, ptr);
171 if (size > 0)171 if (size > 0)
172 {172 {
173 memcpy(ptr, string, (size_t)size);173 memcpy(ptr, string, size);
174 ptr+= size;174 ptr+= size;
175 }175 }
176176
@@ -292,7 +292,7 @@
292}292}
293293
294drizzle_return_t drizzle_unpack_string(drizzle_st *con, char *buffer,294drizzle_return_t drizzle_unpack_string(drizzle_st *con, char *buffer,
295 uint64_t max_length)295 size_t max_length)
296{296{
297 drizzle_return_t ret= DRIZZLE_RETURN_OK;297 drizzle_return_t ret= DRIZZLE_RETURN_OK;
298298
@@ -313,6 +313,18 @@
313 return ret;313 return ret;
314 }314 }
315315
316 if (length > con->packet_size)
317 {
318 drizzle_set_error(con, "drizzle_unpack_string",
319 "string extends past end of packet");
320 return DRIZZLE_RETURN_UNEXPECTED_DATA;
321 }
322 if (length > con->buffer_size)
323 {
324 return DRIZZLE_RETURN_IO_WAIT;
325 }
326
327 assert(max_length > 1);
316 if (length < max_length)328 if (length < max_length)
317 {329 {
318 if (length > 0)330 if (length > 0)
@@ -322,13 +334,13 @@
322 }334 }
323 else335 else
324 {336 {
325 memcpy(buffer, con->buffer_ptr, (size_t)(max_length - 1));337 memcpy(buffer, con->buffer_ptr, max_length - 1);
326 buffer[max_length - 1]= 0;338 buffer[max_length - 1]= 0;
327 }339 }
328 340
329 con->buffer_ptr+= length;341 con->buffer_ptr+= length;
330 con->buffer_size-= (size_t)length;342 con->buffer_size-= length;
331 con->packet_size-= (size_t)length;343 con->packet_size-= (uint32_t)length;
332344
333 return DRIZZLE_RETURN_OK;345 return DRIZZLE_RETURN_OK;
334}346}
335347
=== modified file 'libdrizzle/pack.h'
--- libdrizzle/pack.h 2013-01-27 11:55:48 +0000
+++ libdrizzle/pack.h 2013-03-12 16:48:27 +0000
@@ -85,9 +85,10 @@
8585
86/**86/**
87 * Unpack length-encoded string.87 * Unpack length-encoded string.
88 * max_size is a size_t because it describes the size of the in-core 'buffer'.
88 */89 */
89drizzle_return_t drizzle_unpack_string(drizzle_st *con, char *buffer,90drizzle_return_t drizzle_unpack_string(drizzle_st *con, char *buffer,
90 uint64_t max_size);91 size_t max_size);
9192
92/**93/**
93 * Pack user, scramble, and db.94 * Pack user, scramble, and db.
9495
=== modified file 'libdrizzle/result.cc'
--- libdrizzle/result.cc 2013-01-27 14:00:17 +0000
+++ libdrizzle/result.cc 2013-03-12 16:48:27 +0000
@@ -314,16 +314,20 @@
314314
315 if (result->row_list_size < result->row_count)315 if (result->row_list_size < result->row_count)
316 {316 {
317 row_list= (drizzle_row_t *)realloc(result->row_list, sizeof(drizzle_row_t) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE));317 size_t new_row_list_size = result->row_list_size + DRIZZLE_ROW_GROW_SIZE;
318
319 row_list= (drizzle_row_t *)realloc(result->row_list, sizeof(drizzle_row_t) * new_row_list_size);
318 if (row_list == NULL)320 if (row_list == NULL)
319 {321 {
320 drizzle_row_free(result, row);322 drizzle_row_free(result, row);
321 drizzle_set_error(result->con, __func__, "Failed to realloc row_list.");323 drizzle_set_error(result->con, __func__, "Failed to realloc row_list.");
322 return DRIZZLE_RETURN_MEMORY;324 return DRIZZLE_RETURN_MEMORY;
323 }325 }
326 result->row_list= row_list;
327
324 if (result->binary_rows)328 if (result->binary_rows)
325 {329 {
326 uint8_t **null_bitmap_list= (uint8_t**)realloc(result->null_bitmap_list, sizeof(uint8_t*) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE));330 uint8_t **null_bitmap_list= (uint8_t **)realloc(result->null_bitmap_list, sizeof(uint8_t *) * new_row_list_size);
327 if (null_bitmap_list == NULL)331 if (null_bitmap_list == NULL)
328 {332 {
329 drizzle_row_free(result, row);333 drizzle_row_free(result, row);
@@ -332,19 +336,17 @@
332 }336 }
333 result->null_bitmap_list= null_bitmap_list;337 result->null_bitmap_list= null_bitmap_list;
334 }338 }
335 result->row_list= row_list;
336339
337 field_sizes_list= (size_t **)realloc(result->field_sizes_list, sizeof(size_t *) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE));340 field_sizes_list= (size_t **)realloc(result->field_sizes_list, sizeof(size_t *) * new_row_list_size);
338 if (field_sizes_list == NULL)341 if (field_sizes_list == NULL)
339 {342 {
340 drizzle_row_free(result, row);343 drizzle_row_free(result, row);
341 drizzle_set_error(result->con, "drizzle_result_buffer", "Failed to realloc field list.");344 drizzle_set_error(result->con, "drizzle_result_buffer", "Failed to realloc field list.");
342 return DRIZZLE_RETURN_MEMORY;345 return DRIZZLE_RETURN_MEMORY;
343 }346 }
344
345 result->field_sizes_list= field_sizes_list;347 result->field_sizes_list= field_sizes_list;
346348
347 result->row_list_size+= DRIZZLE_ROW_GROW_SIZE;349 result->row_list_size= new_row_list_size;
348 }350 }
349351
350 if (result->binary_rows)352 if (result->binary_rows)
@@ -460,10 +462,10 @@
460 if (con->packet_size > 0)462 if (con->packet_size > 0)
461 {463 {
462 snprintf(con->last_error, DRIZZLE_MAX_ERROR_SIZE, "%.*s",464 snprintf(con->last_error, DRIZZLE_MAX_ERROR_SIZE, "%.*s",
463 (int32_t)con->packet_size, con->buffer_ptr);465 (int)con->packet_size, con->buffer_ptr);
464 con->last_error[DRIZZLE_MAX_ERROR_SIZE-1]= 0;466 con->last_error[DRIZZLE_MAX_ERROR_SIZE-1]= 0;
465 snprintf(con->result->info, DRIZZLE_MAX_INFO_SIZE, "%.*s",467 snprintf(con->result->info, DRIZZLE_MAX_INFO_SIZE, "%.*s",
466 (int32_t)con->packet_size, con->buffer_ptr);468 (int)con->packet_size, con->buffer_ptr);
467 con->result->info[DRIZZLE_MAX_INFO_SIZE-1]= 0;469 con->result->info[DRIZZLE_MAX_INFO_SIZE-1]= 0;
468 con->buffer_ptr+= con->packet_size;470 con->buffer_ptr+= con->packet_size;
469 con->buffer_size-= con->packet_size;471 con->buffer_size-= con->packet_size;
470472
=== modified file 'libdrizzle/result.h'
--- libdrizzle/result.h 2013-01-27 11:22:49 +0000
+++ libdrizzle/result.h 2013-03-12 16:48:27 +0000
@@ -64,14 +64,14 @@
64 uint64_t row_count;64 uint64_t row_count;
65 uint64_t row_current;65 uint64_t row_current;
6666
67 uint16_t field_current;67 uint16_t field_current; /* field index */
68 size_t field_total;68 uint64_t field_total; /* total length of the field currently being read */
69 size_t field_offset;69 uint64_t field_offset; /* offset within field of most recently read field fragment (0 if first/only fragment) */
70 size_t field_size;70 uint32_t field_size; /* size of most recently read field value or fragment of field value; max 2^24 */
71 drizzle_field_t field;71 drizzle_field_t field;
72 drizzle_field_t field_buffer;72 drizzle_field_t field_buffer;
7373
74 uint64_t row_list_size;74 size_t row_list_size;
75 drizzle_row_t row;75 drizzle_row_t row;
76 drizzle_row_t *row_list;76 drizzle_row_t *row_list;
77 size_t *field_sizes;77 size_t *field_sizes;
@@ -80,7 +80,7 @@
80 bool binlog_checksums;80 bool binlog_checksums;
81 uint8_t **null_bitmap_list;81 uint8_t **null_bitmap_list;
82 uint8_t *null_bitmap;82 uint8_t *null_bitmap;
83 uint8_t null_bitmap_length;83 uint16_t null_bitmap_length;
84 bool binary_rows;84 bool binary_rows;
8585
86 drizzle_result_st() :86 drizzle_result_st() :
8787
=== modified file 'libdrizzle/statement.cc'
--- libdrizzle/statement.cc 2013-01-27 09:48:19 +0000
+++ libdrizzle/statement.cc 2013-03-12 16:48:27 +0000
@@ -320,7 +320,7 @@
320320
321 if (stmt->state < DRIZZLE_STMT_PREPARED)321 if (stmt->state < DRIZZLE_STMT_PREPARED)
322 {322 {
323 drizzle_set_error(stmt->con, __func__, "stmt object has bot been prepared");323 drizzle_set_error(stmt->con, __func__, "stmt object has not been prepared");
324 return DRIZZLE_RETURN_STMT_ERROR;324 return DRIZZLE_RETURN_STMT_ERROR;
325 }325 }
326326
327327
=== modified file 'libdrizzle/statement_param.cc'
--- libdrizzle/statement_param.cc 2013-01-27 11:55:48 +0000
+++ libdrizzle/statement_param.cc 2013-03-12 16:48:27 +0000
@@ -47,7 +47,7 @@
47 }47 }
48 if (stmt->state < DRIZZLE_STMT_PREPARED)48 if (stmt->state < DRIZZLE_STMT_PREPARED)
49 {49 {
50 drizzle_set_error(stmt->con, __func__, "stmt object has bot been prepared");50 drizzle_set_error(stmt->con, __func__, "stmt object has not been prepared");
51 return DRIZZLE_RETURN_STMT_ERROR;51 return DRIZZLE_RETURN_STMT_ERROR;
52 }52 }
5353
@@ -165,6 +165,7 @@
165 if ((stmt == NULL) || (stmt->result_params == NULL))165 if ((stmt == NULL) || (stmt->result_params == NULL))
166 {166 {
167 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;167 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
168 return 0;
168 }169 }
169 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);170 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);
170 if (*ret_ptr != DRIZZLE_RETURN_OK)171 if (*ret_ptr != DRIZZLE_RETURN_OK)
@@ -192,6 +193,7 @@
192 if ((stmt == NULL) || (stmt->result_params == NULL))193 if ((stmt == NULL) || (stmt->result_params == NULL))
193 {194 {
194 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;195 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
196 return 0;
195 }197 }
196 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);198 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);
197 if (*ret_ptr != DRIZZLE_RETURN_OK)199 if (*ret_ptr != DRIZZLE_RETURN_OK)
@@ -219,6 +221,7 @@
219 if ((stmt == NULL) || (stmt->result_params == NULL))221 if ((stmt == NULL) || (stmt->result_params == NULL))
220 {222 {
221 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;223 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
224 return 0;
222 }225 }
223 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);226 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);
224 if (*ret_ptr != DRIZZLE_RETURN_OK)227 if (*ret_ptr != DRIZZLE_RETURN_OK)
@@ -318,6 +321,7 @@
318 if ((stmt == NULL) || (stmt->result_params == NULL))321 if ((stmt == NULL) || (stmt->result_params == NULL))
319 {322 {
320 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;323 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
324 return 0;
321 }325 }
322 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);326 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);
323 if (*ret_ptr != DRIZZLE_RETURN_OK)327 if (*ret_ptr != DRIZZLE_RETURN_OK)
@@ -407,6 +411,7 @@
407 if ((stmt == NULL) || (stmt->result_params == NULL))411 if ((stmt == NULL) || (stmt->result_params == NULL))
408 {412 {
409 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;413 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
414 return 0;
410 }415 }
411 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);416 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);
412 if (*ret_ptr != DRIZZLE_RETURN_OK)417 if (*ret_ptr != DRIZZLE_RETURN_OK)
@@ -418,7 +423,7 @@
418423
419uint64_t drizzle_stmt_get_bigint(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)424uint64_t drizzle_stmt_get_bigint(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)
420{425{
421 uint32_t val;426 uint64_t val;
422 drizzle_bind_st *param;427 drizzle_bind_st *param;
423428
424 if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))429 if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
@@ -492,6 +497,7 @@
492 if ((stmt == NULL) || (stmt->result_params == NULL))497 if ((stmt == NULL) || (stmt->result_params == NULL))
493 {498 {
494 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;499 *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
500 return 0;
495 }501 }
496 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);502 column_number= drizzle_stmt_column_lookup(stmt->prepare_result, column_name, ret_ptr);
497 if (*ret_ptr != DRIZZLE_RETURN_OK)503 if (*ret_ptr != DRIZZLE_RETURN_OK)
498504
=== modified file 'libdrizzle/structs.h'
--- libdrizzle/structs.h 2013-01-27 14:00:17 +0000
+++ libdrizzle/structs.h 2013-03-12 16:48:27 +0000
@@ -208,13 +208,13 @@
208 uint32_t thread_id;208 uint32_t thread_id;
209 int backlog;209 int backlog;
210 socket_t fd;210 socket_t fd;
211 size_t buffer_size;211 size_t buffer_size; /* amount of valid data after 'buffer_ptr' in 'buffer' */
212 size_t command_offset;212 size_t command_offset;
213 size_t command_size;213 size_t command_size;
214 size_t command_total;214 size_t command_total;
215 size_t packet_size;215 uint32_t packet_size; /* remaining number of bytes in packet currently being read; maximum value 2^24 */
216 struct addrinfo *addrinfo_next;216 struct addrinfo *addrinfo_next;
217 unsigned char *buffer_ptr;217 unsigned char *buffer_ptr; /* cursor pointing into 'buffer' */
218 unsigned char *command_buffer;218 unsigned char *command_buffer;
219 unsigned char *command_data;219 unsigned char *command_data;
220 void *context;220 void *context;
@@ -228,7 +228,7 @@
228 drizzle_uds_st uds;228 drizzle_uds_st uds;
229 } socket;229 } socket;
230 unsigned char *buffer;230 unsigned char *buffer;
231 size_t buffer_allocation;231 size_t buffer_allocation; /* total allocated size of 'buffer' */
232 char db[DRIZZLE_MAX_DB_SIZE];232 char db[DRIZZLE_MAX_DB_SIZE];
233 char password[DRIZZLE_MAX_PASSWORD_SIZE];233 char password[DRIZZLE_MAX_PASSWORD_SIZE];
234 unsigned char scramble_buffer[DRIZZLE_MAX_SCRAMBLE_SIZE];234 unsigned char scramble_buffer[DRIZZLE_MAX_SCRAMBLE_SIZE];
@@ -492,7 +492,7 @@
492 uint16_t param_count;492 uint16_t param_count;
493 drizzle_bind_st *query_params;493 drizzle_bind_st *query_params;
494 drizzle_bind_st *result_params;494 drizzle_bind_st *result_params;
495 uint8_t null_bitmap_length;495 uint16_t null_bitmap_length;
496 uint8_t *null_bitmap;496 uint8_t *null_bitmap;
497 bool new_bind;497 bool new_bind;
498 drizzle_result_st *prepare_result;498 drizzle_result_st *prepare_result;
@@ -520,7 +520,7 @@
520 drizzle_column_type_t type;520 drizzle_column_type_t type;
521 void *data;521 void *data;
522 char *data_buffer;522 char *data_buffer;
523 uint32_t length;523 size_t length; /* amount of data in 'data' */
524 bool is_bound;524 bool is_bound;
525 struct options_t525 struct options_t
526 {526 {
527527
=== modified file 'tests/unit/statement.c'
--- tests/unit/statement.c 2013-01-27 09:48:19 +0000
+++ tests/unit/statement.c 2013-03-12 16:48:27 +0000
@@ -103,7 +103,7 @@
103 ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s", drizzle_error(con));103 ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s", drizzle_error(con));
104104
105 /* Result should have 2 rows */105 /* Result should have 2 rows */
106 int count= drizzle_stmt_row_count(stmt);106 uint64_t count = drizzle_stmt_row_count(stmt);
107 ASSERT_EQ_(2, count, "%s", drizzle_error(con));107 ASSERT_EQ_(2, count, "%s", drizzle_error(con));
108108
109 uint32_t i= 1;109 uint32_t i= 1;

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: