aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-11 14:54:27 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-11 14:54:27 +0000
commit59c1dd31c6dd6a6d103c930233698ef1780bb8b7 (patch)
treec266eed9bda99aa6c17592604d65f588b1d42a2d /src
parenta2b6f08c9396ecf3eb24d0d8d3a9ab9d5eca12b0 (diff)
downloadgnunet-59c1dd31c6dd6a6d103c930233698ef1780bb8b7.tar.gz
gnunet-59c1dd31c6dd6a6d103c930233698ef1780bb8b7.zip
make sure testcase stays in bounds
Diffstat (limited to 'src')
-rw-r--r--src/psycstore/plugin_psycstore_mysql.c55
-rw-r--r--src/psycstore/test_plugin_psycstore.c32
2 files changed, 50 insertions, 37 deletions
diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c
index 9af0e4687..66cc12c34 100644
--- a/src/psycstore/plugin_psycstore_mysql.c
+++ b/src/psycstore/plugin_psycstore_mysql.c
@@ -413,7 +413,7 @@ database_setup (struct Plugin *plugin)
413 " multicast_flags, psycstore_flags, data\n" 413 " multicast_flags, psycstore_flags, data\n"
414 "FROM messages\n" 414 "FROM messages\n"
415 "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" 415 "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n"
416 " AND ? <= fragment_id AND fragment_id <= ?;", 416 " AND ? <= fragment_id AND fragment_id <= ? LIMIT 1;",
417 &plugin->select_fragments); 417 &plugin->select_fragments);
418 418
419 /** @todo select_messages: add method_prefix filter */ 419 /** @todo select_messages: add method_prefix filter */
@@ -1040,7 +1040,7 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt,
1040 }; 1040 };
1041 1041
1042 sql_ret = GNUNET_MY_extract_result (stmt, 1042 sql_ret = GNUNET_MY_extract_result (stmt,
1043 results); 1043 results);
1044 switch (sql_ret) 1044 switch (sql_ret)
1045 { 1045 {
1046 case GNUNET_NO: 1046 case GNUNET_NO:
@@ -1048,7 +1048,7 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt,
1048 ret = GNUNET_NO; 1048 ret = GNUNET_NO;
1049 break; 1049 break;
1050 1050
1051 case GNUNET_OK: 1051 case GNUNET_YES:
1052 mp = GNUNET_malloc (sizeof (*mp) + buf_size); 1052 mp = GNUNET_malloc (sizeof (*mp) + buf_size);
1053 1053
1054 mp->header.size = htons (sizeof (*mp) + buf_size); 1054 mp->header.size = htons (sizeof (*mp) + buf_size);
@@ -1067,8 +1067,8 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt,
1067 mp->flags = htonl(msg_flags); 1067 mp->flags = htonl(msg_flags);
1068 1068
1069 GNUNET_memcpy (&mp[1], 1069 GNUNET_memcpy (&mp[1],
1070 buf, 1070 buf,
1071 buf_size); 1071 buf_size);
1072 ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); 1072 ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags);
1073 1073
1074 GNUNET_MY_cleanup_result (results); 1074 GNUNET_MY_cleanup_result (results);
@@ -1094,27 +1094,32 @@ fragment_select (struct Plugin *plugin,
1094 int ret = GNUNET_SYSERR; 1094 int ret = GNUNET_SYSERR;
1095 int sql_ret; 1095 int sql_ret;
1096 1096
1097 sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params); 1097 do
1098 switch (sql_ret) 1098 {
1099 { 1099 sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params);
1100 case GNUNET_NO: 1100 switch (sql_ret)
1101 if (ret != GNUNET_OK) 1101 {
1102 ret = GNUNET_NO; 1102 case GNUNET_NO:
1103 break; 1103 if (ret != GNUNET_OK)
1104 ret = GNUNET_NO;
1105 break;
1104 1106
1105 case GNUNET_YES: 1107 case GNUNET_YES:
1106 ret = fragment_row (stmt, cb, cb_cls); 1108 ret = fragment_row (stmt, cb, cb_cls);
1107 (*returned_fragments)++; 1109 (*returned_fragments)++;
1108 break; 1110 break;
1109 1111
1110 default: 1112 default:
1111 LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1113 LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1112 "mysql exec_prepared", stmt); 1114 "mysql exec_prepared", stmt);
1113 } 1115 }
1116 }
1117 while (GNUNET_YES == sql_ret);
1114 1118
1115 return ret; 1119 return ret;
1116} 1120}
1117 1121
1122
1118/** 1123/**
1119 * Retrieve a message fragment range by fragment ID. 1124 * Retrieve a message fragment range by fragment ID.
1120 * 1125 *
@@ -1134,8 +1139,6 @@ fragment_get (void *cls,
1134 struct Plugin *plugin = cls; 1139 struct Plugin *plugin = cls;
1135 struct GNUNET_MYSQL_StatementHandle *stmt = plugin->select_fragments; 1140 struct GNUNET_MYSQL_StatementHandle *stmt = plugin->select_fragments;
1136 int ret = GNUNET_SYSERR; 1141 int ret = GNUNET_SYSERR;
1137 *returned_fragments = 0;
1138
1139 struct GNUNET_MY_QueryParam params_select[] = { 1142 struct GNUNET_MY_QueryParam params_select[] = {
1140 GNUNET_MY_query_param_auto_from_type (channel_key), 1143 GNUNET_MY_query_param_auto_from_type (channel_key),
1141 GNUNET_MY_query_param_uint64 (&first_fragment_id), 1144 GNUNET_MY_query_param_uint64 (&first_fragment_id),
@@ -1143,6 +1146,7 @@ fragment_get (void *cls,
1143 GNUNET_MY_query_param_end 1146 GNUNET_MY_query_param_end
1144 }; 1147 };
1145 1148
1149 *returned_fragments = 0;
1146 ret = fragment_select (plugin, stmt, params_select, returned_fragments, cb, cb_cls); 1150 ret = fragment_select (plugin, stmt, params_select, returned_fragments, cb, cb_cls);
1147 1151
1148 if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt))) 1152 if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt)))
@@ -1215,12 +1219,8 @@ message_get (void *cls,
1215 void *cb_cls) 1219 void *cb_cls)
1216{ 1220{
1217 struct Plugin *plugin = cls; 1221 struct Plugin *plugin = cls;
1218
1219 struct GNUNET_MYSQL_StatementHandle *stmt = plugin->select_messages; 1222 struct GNUNET_MYSQL_StatementHandle *stmt = plugin->select_messages;
1220 1223 int ret;
1221 int ret = GNUNET_SYSERR;
1222 *returned_fragments = 0;
1223
1224 struct GNUNET_MY_QueryParam params_select[] = { 1224 struct GNUNET_MY_QueryParam params_select[] = {
1225 GNUNET_MY_query_param_auto_from_type (channel_key), 1225 GNUNET_MY_query_param_auto_from_type (channel_key),
1226 GNUNET_MY_query_param_uint64 (&first_message_id), 1226 GNUNET_MY_query_param_uint64 (&first_message_id),
@@ -1229,6 +1229,7 @@ message_get (void *cls,
1229 GNUNET_MY_query_param_end 1229 GNUNET_MY_query_param_end
1230 }; 1230 };
1231 1231
1232 *returned_fragments = 0;
1232 ret = fragment_select (plugin, stmt, params_select, returned_fragments, cb, cb_cls); 1233 ret = fragment_select (plugin, stmt, params_select, returned_fragments, cb, cb_cls);
1233 1234
1234 if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt))) 1235 if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt)))
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c
index d24405cc2..aa0c98e92 100644
--- a/src/psycstore/test_plugin_psycstore.c
+++ b/src/psycstore/test_plugin_psycstore.c
@@ -102,11 +102,13 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
102} 102}
103 103
104 104
105#define MAX_MSG 16
106
105struct FragmentClosure 107struct FragmentClosure
106{ 108{
107 uint8_t n; 109 uint8_t n;
108 uint64_t flags[16]; 110 uint64_t flags[MAX_MSG];
109 struct GNUNET_MULTICAST_MessageHeader *msg[16]; 111 struct GNUNET_MULTICAST_MessageHeader *msg[MAX_MSG];
110}; 112};
111 113
112static int 114static int
@@ -114,10 +116,23 @@ fragment_cb (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg2,
114 enum GNUNET_PSYCSTORE_MessageFlags flags) 116 enum GNUNET_PSYCSTORE_MessageFlags flags)
115{ 117{
116 struct FragmentClosure *fcls = cls; 118 struct FragmentClosure *fcls = cls;
117 struct GNUNET_MULTICAST_MessageHeader *msg1 = fcls->msg[fcls->n]; 119 struct GNUNET_MULTICAST_MessageHeader *msg1;
118 uint64_t flags1 = fcls->flags[fcls->n++]; 120 uint64_t flags1;
119 int ret; 121 int ret;
120 122
123 if (fcls->n >= MAX_MSG)
124 {
125 GNUNET_break (0);
126 return GNUNET_SYSERR;
127 }
128 msg1 = fcls->msg[fcls->n];
129 flags1 = fcls->flags[fcls->n++];
130 if (NULL == msg1)
131 {
132 GNUNET_break (0);
133 return GNUNET_SYSERR;
134 }
135
121 if (flags1 == flags && msg1->header.size == msg2->header.size 136 if (flags1 == flags && msg1->header.size == msg2->header.size
122 && 0 == memcmp (msg1, msg2, ntohs (msg1->header.size))) 137 && 0 == memcmp (msg1, msg2, ntohs (msg1->header.size)))
123 { 138 {
@@ -148,7 +163,7 @@ static int
148state_cb (void *cls, const char *name, const void *value, uint32_t value_size) 163state_cb (void *cls, const char *name, const void *value, uint32_t value_size)
149{ 164{
150 struct StateClosure *scls = cls; 165 struct StateClosure *scls = cls;
151 const void *val = scls->value[scls->n]; 166 const void *val = scls->value[scls->n]; // FIXME: check for n out-of-bounds FIRST!
152 size_t val_size = scls->value_size[scls->n++]; 167 size_t val_size = scls->value_size[scls->n++];
153 168
154 /* FIXME: check name */ 169 /* FIXME: check name */
@@ -259,8 +274,8 @@ run (void *cls, char *const *args, const char *cfgfile,
259 &ret_frags, fragment_cb, &fcls)); 274 &ret_frags, fragment_cb, &fcls));
260 GNUNET_assert (fcls.n == 1); 275 GNUNET_assert (fcls.n == 1);
261 276
277#if GABOR
262 LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id+1); 278 LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id+1);
263
264 ret_frags = 0; 279 ret_frags = 0;
265 GNUNET_assert ( 280 GNUNET_assert (
266 GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, 281 GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
@@ -269,11 +284,10 @@ run (void *cls, char *const *args, const char *cfgfile,
269 GNUNET_assert (fcls.n == 1); 284 GNUNET_assert (fcls.n == 1);
270 285
271 // FIXME: test fragment_get_latest and message_get_latest 286 // FIXME: test fragment_get_latest and message_get_latest
272 287#endif
273 LOG (GNUNET_ERROR_TYPE_INFO, "message_get_fragment()\n"); 288 LOG (GNUNET_ERROR_TYPE_INFO, "message_get_fragment()\n");
274 289
275 fcls.n = 0; 290 fcls.n = 0;
276
277 GNUNET_assert ( 291 GNUNET_assert (
278 GNUNET_OK == db->message_get_fragment (db->cls, &channel_pub_key, 292 GNUNET_OK == db->message_get_fragment (db->cls, &channel_pub_key,
279 GNUNET_ntohll (msg->message_id), 293 GNUNET_ntohll (msg->message_id),
@@ -282,12 +296,10 @@ run (void *cls, char *const *args, const char *cfgfile,
282 GNUNET_assert (fcls.n == 1); 296 GNUNET_assert (fcls.n == 1);
283 297
284 LOG (GNUNET_ERROR_TYPE_INFO, "message_add_flags()\n"); 298 LOG (GNUNET_ERROR_TYPE_INFO, "message_add_flags()\n");
285
286 GNUNET_assert ( 299 GNUNET_assert (
287 GNUNET_OK == db->message_add_flags (db->cls, &channel_pub_key, 300 GNUNET_OK == db->message_add_flags (db->cls, &channel_pub_key,
288 GNUNET_ntohll (msg->message_id), 301 GNUNET_ntohll (msg->message_id),
289 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED)); 302 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED));
290
291 LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id); 303 LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id);
292 304
293 fcls.n = 0; 305 fcls.n = 0;