diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-24 20:12:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-24 20:12:53 +0000 |
commit | d5fd881c2a044474b54ddf03b6ab8be8d2b75927 (patch) | |
tree | b3565f8038b761a2a2117476dc7d493fc8e0cde2 /src | |
parent | 63b2e5ce20544b22da822848d6e3f3c495f381c3 (diff) | |
download | gnunet-d5fd881c2a044474b54ddf03b6ab8be8d2b75927.tar.gz gnunet-d5fd881c2a044474b54ddf03b6ab8be8d2b75927.zip |
-handle NULL results
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_my_lib.h | 5 | ||||
-rw-r--r-- | src/my/my.c | 42 | ||||
-rw-r--r-- | src/my/my_result_helper.c | 43 |
3 files changed, 70 insertions, 20 deletions
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index 61fd6459f..6ecff67a0 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h | |||
@@ -246,6 +246,11 @@ struct GNUNET_MY_ResultSpec | |||
246 | */ | 246 | */ |
247 | unsigned long mysql_bind_output_length; | 247 | unsigned long mysql_bind_output_length; |
248 | 248 | ||
249 | /** | ||
250 | * Memory for MySQL to notify us about NULL values. | ||
251 | */ | ||
252 | my_bool is_null; | ||
253 | |||
249 | }; | 254 | }; |
250 | 255 | ||
251 | 256 | ||
diff --git a/src/my/my.c b/src/my/my.c index ae46a2888..5ca80b63c 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -75,9 +75,11 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
75 | if (mysql_stmt_bind_param (stmt, | 75 | if (mysql_stmt_bind_param (stmt, |
76 | qbind)) | 76 | qbind)) |
77 | { | 77 | { |
78 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 78 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
79 | "my", | ||
79 | _("`%s' failed at %s:%d with error: %s\n"), | 80 | _("`%s' failed at %s:%d with error: %s\n"), |
80 | "mysql_stmt_bind_param", __FILE__, __LINE__, | 81 | "mysql_stmt_bind_param", |
82 | __FILE__, __LINE__, | ||
81 | mysql_stmt_error (stmt)); | 83 | mysql_stmt_error (stmt)); |
82 | GNUNET_MYSQL_statements_invalidate (mc); | 84 | GNUNET_MYSQL_statements_invalidate (mc); |
83 | return GNUNET_SYSERR; | 85 | return GNUNET_SYSERR; |
@@ -85,18 +87,17 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
85 | 87 | ||
86 | if (mysql_stmt_execute (stmt)) | 88 | if (mysql_stmt_execute (stmt)) |
87 | { | 89 | { |
88 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 90 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
91 | "my", | ||
89 | _("`%s' failed at %s:%d with error: %s\n"), | 92 | _("`%s' failed at %s:%d with error: %s\n"), |
90 | "mysql_stmt_execute", __FILE__, __LINE__, | 93 | "mysql_stmt_execute", __FILE__, __LINE__, |
91 | mysql_stmt_error (stmt)); | 94 | mysql_stmt_error (stmt)); |
92 | GNUNET_MYSQL_statements_invalidate (mc); | 95 | GNUNET_MYSQL_statements_invalidate (mc); |
93 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
94 | } | 97 | } |
95 | |||
96 | GNUNET_MY_cleanup_query (params, | 98 | GNUNET_MY_cleanup_query (params, |
97 | qbind); | 99 | qbind); |
98 | } | 100 | } |
99 | |||
100 | return GNUNET_OK; | 101 | return GNUNET_OK; |
101 | } | 102 | } |
102 | 103 | ||
@@ -125,7 +126,6 @@ GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, | |||
125 | * Extract results from a query result according to the given | 126 | * Extract results from a query result according to the given |
126 | * specification. Always fetches the next row. | 127 | * specification. Always fetches the next row. |
127 | * | 128 | * |
128 | * | ||
129 | * @param sh statement that returned results | 129 | * @param sh statement that returned results |
130 | * @param rs specification to extract for | 130 | * @param rs specification to extract for |
131 | * @return | 131 | * @return |
@@ -145,12 +145,14 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
145 | stmt = GNUNET_MYSQL_statement_get_stmt (sh); | 145 | stmt = GNUNET_MYSQL_statement_get_stmt (sh); |
146 | if (NULL == stmt) | 146 | if (NULL == stmt) |
147 | { | 147 | { |
148 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 148 | GNUNET_break (0); |
149 | ("`%s' failed at %s:%d with error: %s\n"), | ||
150 | "mysql_stmt_bind_result", __FILE__, __LINE__, | ||
151 | mysql_stmt_error (stmt)); | ||
152 | return GNUNET_SYSERR; | 149 | return GNUNET_SYSERR; |
153 | } | 150 | } |
151 | if (NULL == rs) | ||
152 | { | ||
153 | mysql_stmt_free_result (stmt); | ||
154 | return GNUNET_NO; | ||
155 | } | ||
154 | 156 | ||
155 | num_fields = 0; | 157 | num_fields = 0; |
156 | for (i=0;NULL != rs[i].pre_conv;i++) | 158 | for (i=0;NULL != rs[i].pre_conv;i++) |
@@ -187,25 +189,32 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
187 | } | 189 | } |
188 | field_off += rp->num_fields; | 190 | field_off += rp->num_fields; |
189 | } | 191 | } |
192 | |||
190 | if (mysql_stmt_bind_result (stmt, result)) | 193 | if (mysql_stmt_bind_result (stmt, result)) |
191 | { | 194 | { |
192 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 195 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
193 | "my", | 196 | "my", |
194 | _("`%s' failed at %s:%d with error: %s\n"), | 197 | _("%s failed at %s:%d with error: %s\n"), |
195 | "mysql_stmt_bind_result", __FILE__, __LINE__, | 198 | "mysql_stmt_bind_result", |
199 | __FILE__, __LINE__, | ||
196 | mysql_stmt_error (stmt)); | 200 | mysql_stmt_error (stmt)); |
197 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
198 | } | 202 | } |
199 | 203 | #if TEST_OPTIMIZATION | |
204 | (void) mysql_stmt_store_result (stmt); | ||
205 | #endif | ||
200 | ret = mysql_stmt_fetch (stmt); | 206 | ret = mysql_stmt_fetch (stmt); |
201 | |||
202 | if (MYSQL_NO_DATA == ret) | 207 | if (MYSQL_NO_DATA == ret) |
208 | { | ||
209 | mysql_stmt_free_result (stmt); | ||
203 | return GNUNET_NO; | 210 | return GNUNET_NO; |
204 | if ((0 != ret ) && (MYSQL_DATA_TRUNCATED != ret)) | 211 | } |
212 | if (1 == ret) | ||
205 | { | 213 | { |
206 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 214 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
207 | "my", | 215 | "my", |
208 | _("mysql_stmt_fetch failed at %s:%d with error: %s\n"), | 216 | _("%s failed at %s:%d with error: %s\n"), |
217 | "mysql_stmt_fetch", | ||
209 | __FILE__, __LINE__, | 218 | __FILE__, __LINE__, |
210 | mysql_stmt_error (stmt)); | 219 | mysql_stmt_error (stmt)); |
211 | GNUNET_MY_cleanup_result (rs); | 220 | GNUNET_MY_cleanup_result (rs); |
@@ -235,7 +244,6 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
235 | field_off += rp->num_fields; | 244 | field_off += rp->num_fields; |
236 | } | 245 | } |
237 | } | 246 | } |
238 | mysql_stmt_free_result (stmt); | ||
239 | return GNUNET_OK; | 247 | return GNUNET_OK; |
240 | } | 248 | } |
241 | 249 | ||
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index a91a24d90..bee6e3304 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_result_helper.c | |||
@@ -46,6 +46,8 @@ pre_extract_varsize_blob (void *cls, | |||
46 | results[0].buffer = NULL; | 46 | results[0].buffer = NULL; |
47 | results[0].buffer_length = 0; | 47 | results[0].buffer_length = 0; |
48 | results[0].length = &rs->mysql_bind_output_length; | 48 | results[0].length = &rs->mysql_bind_output_length; |
49 | results[0].is_null = &rs->is_null; | ||
50 | rs->is_null = 0; | ||
49 | 51 | ||
50 | return GNUNET_OK; | 52 | return GNUNET_OK; |
51 | } | 53 | } |
@@ -73,6 +75,8 @@ post_extract_varsize_blob (void *cls, | |||
73 | void *buf; | 75 | void *buf; |
74 | size_t size; | 76 | size_t size; |
75 | 77 | ||
78 | if (*results->is_null) | ||
79 | return GNUNET_SYSERR; | ||
76 | size = (size_t) rs->mysql_bind_output_length; | 80 | size = (size_t) rs->mysql_bind_output_length; |
77 | 81 | ||
78 | if (rs->mysql_bind_output_length != size) | 82 | if (rs->mysql_bind_output_length != size) |
@@ -169,6 +173,8 @@ pre_extract_fixed_blob (void *cls, | |||
169 | results[0].buffer_length = rs->dst_size; | 173 | results[0].buffer_length = rs->dst_size; |
170 | results[0].length = &rs->mysql_bind_output_length; | 174 | results[0].length = &rs->mysql_bind_output_length; |
171 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 175 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
176 | results[0].is_null = &rs->is_null; | ||
177 | rs->is_null = 0; | ||
172 | 178 | ||
173 | return GNUNET_OK; | 179 | return GNUNET_OK; |
174 | } | 180 | } |
@@ -194,6 +200,8 @@ post_extract_fixed_blob (void *cls, | |||
194 | unsigned int column, | 200 | unsigned int column, |
195 | MYSQL_BIND *results) | 201 | MYSQL_BIND *results) |
196 | { | 202 | { |
203 | if (*results->is_null) | ||
204 | return GNUNET_SYSERR; | ||
197 | if (rs->dst_size != rs->mysql_bind_output_length) | 205 | if (rs->dst_size != rs->mysql_bind_output_length) |
198 | return GNUNET_SYSERR; | 206 | return GNUNET_SYSERR; |
199 | return GNUNET_OK; | 207 | return GNUNET_OK; |
@@ -249,6 +257,8 @@ pre_extract_rsa_public_key (void *cls, | |||
249 | results[0].buffer_length = 0; | 257 | results[0].buffer_length = 0; |
250 | results[0].length = &rs->mysql_bind_output_length; | 258 | results[0].length = &rs->mysql_bind_output_length; |
251 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 259 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
260 | results[0].is_null = &rs->is_null; | ||
261 | rs->is_null = 0; | ||
252 | 262 | ||
253 | return GNUNET_OK; | 263 | return GNUNET_OK; |
254 | } | 264 | } |
@@ -279,6 +289,8 @@ post_extract_rsa_public_key (void *cls, | |||
279 | void *buf; | 289 | void *buf; |
280 | size_t size; | 290 | size_t size; |
281 | 291 | ||
292 | if (*results->is_null) | ||
293 | return GNUNET_SYSERR; | ||
282 | size = (size_t) rs->mysql_bind_output_length; | 294 | size = (size_t) rs->mysql_bind_output_length; |
283 | 295 | ||
284 | if (rs->mysql_bind_output_length != size) | 296 | if (rs->mysql_bind_output_length != size) |
@@ -379,6 +391,8 @@ pre_extract_rsa_signature (void *cls, | |||
379 | results[0].buffer_length = 0; | 391 | results[0].buffer_length = 0; |
380 | results[0].length = &rs->mysql_bind_output_length; | 392 | results[0].length = &rs->mysql_bind_output_length; |
381 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 393 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
394 | results[0].is_null = &rs->is_null; | ||
395 | rs->is_null = 0; | ||
382 | 396 | ||
383 | return GNUNET_OK; | 397 | return GNUNET_OK; |
384 | } | 398 | } |
@@ -407,6 +421,8 @@ post_extract_rsa_signature (void *cls, | |||
407 | void *buf; | 421 | void *buf; |
408 | size_t size; | 422 | size_t size; |
409 | 423 | ||
424 | if (*results->is_null) | ||
425 | return GNUNET_SYSERR; | ||
410 | size = (size_t) rs->mysql_bind_output_length; | 426 | size = (size_t) rs->mysql_bind_output_length; |
411 | 427 | ||
412 | if (rs->mysql_bind_output_length != size) | 428 | if (rs->mysql_bind_output_length != size) |
@@ -448,7 +464,7 @@ post_extract_rsa_signature (void *cls, | |||
448 | */ | 464 | */ |
449 | static void | 465 | static void |
450 | clean_rsa_signature (void *cls, | 466 | clean_rsa_signature (void *cls, |
451 | struct GNUNET_MY_ResultSpec *rs) | 467 | struct GNUNET_MY_ResultSpec *rs) |
452 | { | 468 | { |
453 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; | 469 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; |
454 | 470 | ||
@@ -505,6 +521,8 @@ pre_extract_string (void * cls, | |||
505 | results[0].buffer_length = 0; | 521 | results[0].buffer_length = 0; |
506 | results[0].length = &rs->mysql_bind_output_length; | 522 | results[0].length = &rs->mysql_bind_output_length; |
507 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 523 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
524 | results[0].is_null = &rs->is_null; | ||
525 | rs->is_null = 0; | ||
508 | 526 | ||
509 | return GNUNET_OK; | 527 | return GNUNET_OK; |
510 | } | 528 | } |
@@ -534,6 +552,11 @@ post_extract_string (void * cls, | |||
534 | 552 | ||
535 | if (rs->mysql_bind_output_length != size) | 553 | if (rs->mysql_bind_output_length != size) |
536 | return GNUNET_SYSERR; | 554 | return GNUNET_SYSERR; |
555 | if (*results->is_null) | ||
556 | { | ||
557 | rs->dst = NULL; | ||
558 | return GNUNET_OK; | ||
559 | } | ||
537 | 560 | ||
538 | buf = GNUNET_malloc (size); | 561 | buf = GNUNET_malloc (size); |
539 | results[0].buffer = buf; | 562 | results[0].buffer = buf; |
@@ -627,6 +650,8 @@ pre_extract_uint16 (void *cls, | |||
627 | results[0].buffer_length = rs->dst_size; | 650 | results[0].buffer_length = rs->dst_size; |
628 | results[0].length = &rs->mysql_bind_output_length; | 651 | results[0].length = &rs->mysql_bind_output_length; |
629 | results[0].buffer_type = MYSQL_TYPE_SHORT; | 652 | results[0].buffer_type = MYSQL_TYPE_SHORT; |
653 | results[0].is_null = &rs->is_null; | ||
654 | rs->is_null = 0; | ||
630 | 655 | ||
631 | return GNUNET_OK; | 656 | return GNUNET_OK; |
632 | } | 657 | } |
@@ -653,6 +678,8 @@ post_extract_uint16 (void *cls, | |||
653 | { | 678 | { |
654 | if (rs->dst_size != rs->mysql_bind_output_length) | 679 | if (rs->dst_size != rs->mysql_bind_output_length) |
655 | return GNUNET_SYSERR; | 680 | return GNUNET_SYSERR; |
681 | if (*results->is_null) | ||
682 | return GNUNET_SYSERR; | ||
656 | return GNUNET_OK; | 683 | return GNUNET_OK; |
657 | } | 684 | } |
658 | 685 | ||
@@ -702,6 +729,8 @@ pre_extract_uint32 (void *cls, | |||
702 | results[0].buffer_length = rs->dst_size; | 729 | results[0].buffer_length = rs->dst_size; |
703 | results[0].length = &rs->mysql_bind_output_length; | 730 | results[0].length = &rs->mysql_bind_output_length; |
704 | results[0].buffer_type = MYSQL_TYPE_LONG; | 731 | results[0].buffer_type = MYSQL_TYPE_LONG; |
732 | results[0].is_null = &rs->is_null; | ||
733 | rs->is_null = 0; | ||
705 | 734 | ||
706 | return GNUNET_OK; | 735 | return GNUNET_OK; |
707 | } | 736 | } |
@@ -728,7 +757,9 @@ post_extract_uint32 (void *cls, | |||
728 | MYSQL_BIND *results) | 757 | MYSQL_BIND *results) |
729 | { | 758 | { |
730 | if (rs->dst_size != rs->mysql_bind_output_length) | 759 | if (rs->dst_size != rs->mysql_bind_output_length) |
731 | return GNUNET_SYSERR; | 760 | return GNUNET_SYSERR; |
761 | if (*results->is_null) | ||
762 | return GNUNET_SYSERR; | ||
732 | return GNUNET_OK; | 763 | return GNUNET_OK; |
733 | } | 764 | } |
734 | 765 | ||
@@ -773,10 +804,14 @@ pre_extract_uint64 (void *cls, | |||
773 | unsigned int column, | 804 | unsigned int column, |
774 | MYSQL_BIND *results) | 805 | MYSQL_BIND *results) |
775 | { | 806 | { |
807 | if (sizeof (uint64_t) != rs->dst_size) | ||
808 | return GNUNET_SYSERR; | ||
776 | results[0].buffer = rs->dst; | 809 | results[0].buffer = rs->dst; |
777 | results[0].buffer_length = rs->dst_size; | 810 | results[0].buffer_length = rs->dst_size; |
778 | results[0].length = &rs->mysql_bind_output_length; | 811 | results[0].length = &rs->mysql_bind_output_length; |
779 | results[0].buffer_type = MYSQL_TYPE_LONGLONG; | 812 | results[0].buffer_type = MYSQL_TYPE_LONGLONG; |
813 | results[0].is_null = &rs->is_null; | ||
814 | rs->is_null = 0; | ||
780 | 815 | ||
781 | return GNUNET_OK; | 816 | return GNUNET_OK; |
782 | } | 817 | } |
@@ -801,7 +836,9 @@ post_extract_uint64 (void *cls, | |||
801 | unsigned int column, | 836 | unsigned int column, |
802 | MYSQL_BIND *results) | 837 | MYSQL_BIND *results) |
803 | { | 838 | { |
804 | if (rs->dst_size != rs->mysql_bind_output_length) | 839 | if (sizeof (uint64_t) != rs->dst_size) |
840 | return GNUNET_SYSERR; | ||
841 | if (*results->is_null) | ||
805 | return GNUNET_SYSERR; | 842 | return GNUNET_SYSERR; |
806 | return GNUNET_OK; | 843 | return GNUNET_OK; |
807 | } | 844 | } |