aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore/plugin_psycstore_mysql.c
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/psycstore/plugin_psycstore_mysql.c
parenta2b6f08c9396ecf3eb24d0d8d3a9ab9d5eca12b0 (diff)
downloadgnunet-59c1dd31c6dd6a6d103c930233698ef1780bb8b7.tar.gz
gnunet-59c1dd31c6dd6a6d103c930233698ef1780bb8b7.zip
make sure testcase stays in bounds
Diffstat (limited to 'src/psycstore/plugin_psycstore_mysql.c')
-rw-r--r--src/psycstore/plugin_psycstore_mysql.c55
1 files changed, 28 insertions, 27 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)))