From 5c4b060714954a6e4571fe981b333856d2ef4a1b Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Thu, 8 Dec 2022 17:30:22 +0900 Subject: TESTING: The testing API should properly take strings as const Strings passed to the API should either be const and copied, or handled by the caller and free'd. Looking at the transport tests currently neither is happening. The strings are probably safer but definitely leaked. Changed the API to use "const" strings. Users of the testing API must define functions that copy (and free!) strings accordingly. --- src/include/gnunet_testing_plugin.h | 19 +++++++++++-------- src/testing/gnunet-cmds-helper.c | 3 ++- src/transport/test_transport_plugin_cmd_nat_upnp.c | 13 +++++++------ src/transport/test_transport_plugin_cmd_simple_send.c | 13 +++++++------ .../test_transport_plugin_cmd_simple_send_broadcast.c | 13 +++++++------ .../test_transport_plugin_cmd_simple_send_dv.c | 13 +++++++------ .../test_transport_plugin_cmd_udp_backchannel.c | 13 +++++++------ src/transport/transport-testing-cmds.h | 8 +++++--- src/transport/transport_api_cmd_start_peer.c | 16 +--------------- 9 files changed, 54 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h index 28b505976..6c1b9c1a9 100644 --- a/src/include/gnunet_testing_plugin.h +++ b/src/include/gnunet_testing_plugin.h @@ -28,6 +28,8 @@ #ifndef GNUNET_TESTING_PLUGIN_H #define GNUNET_TESTING_PLUGIN_H +#include "gnunet_common.h" + #ifdef __cplusplus extern "C" { @@ -37,20 +39,21 @@ extern "C" #endif typedef void -(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t - msg_length); +(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, + size_t msg_length); typedef void (*TESTING_CMD_HELPER_finish_cb) (); typedef void (*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb - write_message, char *router_ip, - char *node_ip, - char *n, - char *m, - char *local_m, - char *topology_data, + write_message, + const char *router_ip, + const char *node_ip, + const char *n, + const char *m, + const char *local_m, + const char *topology_data, unsigned int *read_file, TESTING_CMD_HELPER_finish_cb finish_cb); diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c index 624aa58eb..591ddd499 100644 --- a/src/testing/gnunet-cmds-helper.c +++ b/src/testing/gnunet-cmds-helper.c @@ -385,6 +385,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) LOG (GNUNET_ERROR_TYPE_ERROR, "subnet node n: %s\n", plugin->n); + // FIXME: Free? node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1); strcat (node_ip, NODE_BASE_IP); } @@ -622,7 +623,7 @@ main (int argc, char **argv) } shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); - + ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-cmds-helper", diff --git a/src/transport/test_transport_plugin_cmd_nat_upnp.c b/src/transport/test_transport_plugin_cmd_nat_upnp.c index 86280c66b..73380e03c 100644 --- a/src/transport/test_transport_plugin_cmd_nat_upnp.c +++ b/src/transport/test_transport_plugin_cmd_nat_upnp.c @@ -210,12 +210,13 @@ all_local_tests_prepared () * @param local_m The number of nodes in a network namespace. */ static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, - char *node_ip, - char *m, - char *n, - char *local_m, - char *topology_data, +start_testcase (TESTING_CMD_HELPER_write_cb write_message, + const char *router_ip, + const char *node_ip, + const char *m, + const char *n, + const char *local_m, + const char *topology_data, unsigned int *read_file, TESTING_CMD_HELPER_finish_cb finished_cb) { diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index c9acb0431..de923cbdd 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c @@ -202,12 +202,13 @@ all_local_tests_prepared () * @param local_m The number of nodes in a network namespace. */ static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, - char *node_ip, - char *m, - char *n, - char *local_m, - char *topology_data, +start_testcase (TESTING_CMD_HELPER_write_cb write_message, + const char *router_ip, + const char *node_ip, + const char *m, + const char *n, + const char *local_m, + const char *topology_data, unsigned int *read_file, TESTING_CMD_HELPER_finish_cb finished_cb) { diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c index f7a4b117f..ff6f0def9 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c +++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c @@ -235,12 +235,13 @@ all_local_tests_prepared () * @param local_m The number of nodes in a network namespace. */ static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, - char *node_ip, - char *m, - char *n, - char *local_m, - char *topology_data, +start_testcase (TESTING_CMD_HELPER_write_cb write_message, + const char *router_ip, + const char *node_ip, + const char *m, + const char *n, + const char *local_m, + const char *topology_data, unsigned int *read_file, TESTING_CMD_HELPER_finish_cb finished_cb) { diff --git a/src/transport/test_transport_plugin_cmd_simple_send_dv.c b/src/transport/test_transport_plugin_cmd_simple_send_dv.c index 674c0d576..adbb3cc0b 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send_dv.c +++ b/src/transport/test_transport_plugin_cmd_simple_send_dv.c @@ -258,12 +258,13 @@ all_local_tests_prepared () * @param local_m The number of nodes in a network namespace. */ static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, - char *node_ip, - char *m, - char *n, - char *local_m, - char *topology_data, +start_testcase (TESTING_CMD_HELPER_write_cb write_message, + const char *router_ip, + const char *node_ip, + const char *m, + const char *n, + const char *local_m, + const char *topology_data, unsigned int *read_file, TESTING_CMD_HELPER_finish_cb finished_cb) { diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index 38b81da85..81445b25e 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c @@ -195,12 +195,13 @@ all_local_tests_prepared () * @param local_m The number of nodes in a network namespace. */ static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, - char *node_ip, - char *m, - char *n, - char *local_m, - char *topology_data, +start_testcase (TESTING_CMD_HELPER_write_cb write_message, + const char *router_ip, + const char *node_ip, + const char *m, + const char *n, + const char *local_m, + const char *topology_data, unsigned int *read_file, TESTING_CMD_HELPER_finish_cb finished_cb) { diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index c577feb34..680162563 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h @@ -26,7 +26,7 @@ */ #ifndef TRANSPORT_TESTING_CMDS_H #define TRANSPORT_TESTING_CMDS_H -#include "gnunet_testing_lib.h" +#include "gnunet_testing_ng_lib.h" typedef void * @@ -109,7 +109,7 @@ struct StartPeerState /** * The ip of a node. */ - char *node_ip; + const char *node_ip; /** * Receive callback @@ -193,6 +193,8 @@ struct StartPeerState /** * Create command. + * FIXME: Parameter list does not match documentation. + * FIXME: m and n parameters need a rename. * * @param label name for command. * @param system_label Label of the cmd to setup a test environment. @@ -209,7 +211,7 @@ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer (const char *label, const char *system_label, uint32_t no, - char *node_ip, + const char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, GNUNET_TRANSPORT_notify_connect_cb diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index 4add06609..5dfb820e0 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -431,25 +431,11 @@ start_peer_traits (void *cls, } -/** - * Create command. - * - * @param label name for command. - * @param system_label Label of the cmd to setup a test environment. - * @param m The number of the local node of the actual network namespace. - * @param n The number of the actual namespace. - * @param local_m Number of local nodes in each namespace. - * @param handlers Handler for messages received by this peer. - * @param cfgname Configuration file name for this peer. - * @param notify_connect Method which will be called, when a peer connects. - * @param broadcast Flag indicating, if broadcast should be switched on. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer (const char *label, const char *system_label, uint32_t no, - char *node_ip, + const char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, GNUNET_TRANSPORT_notify_connect_cb -- cgit v1.2.3