diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-08 20:51:35 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-08 20:51:35 +0900 |
commit | 7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e (patch) | |
tree | aaabeaa4b8e8a0afe82d8d7538d271525105da48 /src/testing/testing_api_loop.c | |
parent | dccf4142eaac44711692c295d81e0103c8042cd2 (diff) | |
download | gnunet-7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e.tar.gz gnunet-7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e.zip |
TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API
This commit changes the label member of GNUNET_TRANSPORT_Command to a
static, fixed length buffer allocated with the struct itself.
The check for the end of a command array should be done by checking the
run command instead of the label.
Diffstat (limited to 'src/testing/testing_api_loop.c')
-rw-r--r-- | src/testing/testing_api_loop.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index a3a8219b3..da95500f7 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c | |||
@@ -149,12 +149,12 @@ get_command (struct GNUNET_TESTING_Interpreter *is, | |||
149 | { | 149 | { |
150 | const struct GNUNET_TESTING_Command *cmd = &is->commands[i]; | 150 | const struct GNUNET_TESTING_Command *cmd = &is->commands[i]; |
151 | 151 | ||
152 | if (NULL != cmd->label) | 152 | if (NULL != cmd->run) |
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "label to compare %s\n", | 154 | "label to compare %s\n", |
155 | cmd->label); | 155 | cmd->label); |
156 | /* Give precedence to top-level commands. */ | 156 | /* Give precedence to top-level commands. */ |
157 | if ( (NULL != cmd->label) && | 157 | if ( (NULL != cmd->run) && |
158 | (0 == strcmp (cmd->label, | 158 | (0 == strcmp (cmd->label, |
159 | label)) ) | 159 | label)) ) |
160 | return cmd; | 160 | return cmd; |
@@ -173,12 +173,12 @@ get_command (struct GNUNET_TESTING_Interpreter *is, | |||
173 | /* We must do the loop forward, but we can find the last match */ | 173 | /* We must do the loop forward, but we can find the last match */ |
174 | match = NULL; | 174 | match = NULL; |
175 | for (unsigned int j = 0; | 175 | for (unsigned int j = 0; |
176 | NULL != (icmd = &(*batch)[j])->label; | 176 | NULL != (icmd = &(*batch)[j])->run; |
177 | j++) | 177 | j++) |
178 | { | 178 | { |
179 | if (current == icmd) | 179 | if (current == icmd) |
180 | break; /* do not go past current command */ | 180 | break; /* do not go past current command */ |
181 | if ( (NULL != icmd->label) && | 181 | if ( (NULL != icmd->run) && |
182 | (0 == strcmp (icmd->label, | 182 | (0 == strcmp (icmd->label, |
183 | label)) ) | 183 | label)) ) |
184 | match = icmd; | 184 | match = icmd; |
@@ -264,14 +264,13 @@ finish_test (void *cls) | |||
264 | label, | 264 | label, |
265 | is->result); | 265 | is->result); |
266 | for (unsigned int j = 0; | 266 | for (unsigned int j = 0; |
267 | NULL != (cmd = &is->commands[j])->label; | 267 | NULL != (cmd = &is->commands[j])->run; |
268 | j++) | 268 | j++) |
269 | { | 269 | { |
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
271 | "Cleaning up cmd %s\n", | 271 | "Cleaning up cmd %s\n", |
272 | cmd->label); | 272 | cmd->label); |
273 | cmd->cleanup (cmd->cls); | 273 | cmd->cleanup (cmd->cls); |
274 | GNUNET_free (cmd->label); | ||
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
276 | "Cleaned up cmd %s\n", | 275 | "Cleaned up cmd %s\n", |
277 | cmd->label); | 276 | cmd->label); |
@@ -407,7 +406,7 @@ interpreter_run (void *cls) | |||
407 | struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; | 406 | struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; |
408 | 407 | ||
409 | is->task = NULL; | 408 | is->task = NULL; |
410 | if (NULL == cmd->label) | 409 | if (NULL == cmd->run) |
411 | { | 410 | { |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
413 | "Running command END\n"); | 412 | "Running command END\n"); |
@@ -490,7 +489,7 @@ GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command) | |||
490 | 489 | ||
491 | 490 | ||
492 | struct GNUNET_TESTING_Interpreter * | 491 | struct GNUNET_TESTING_Interpreter * |
493 | GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | 492 | GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, |
494 | struct GNUNET_TIME_Relative timeout, | 493 | struct GNUNET_TIME_Relative timeout, |
495 | GNUNET_TESTING_ResultCallback rc, | 494 | GNUNET_TESTING_ResultCallback rc, |
496 | void *rc_cls) | 495 | void *rc_cls) |
@@ -503,7 +502,7 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | |||
503 | is->rc_cls = rc_cls; | 502 | is->rc_cls = rc_cls; |
504 | is->barriers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | 503 | is->barriers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); |
505 | /* get the number of commands */ | 504 | /* get the number of commands */ |
506 | for (i = 0; NULL != commands[i].label; i++) | 505 | for (i = 0; NULL != commands[i].run; i++) |
507 | ; | 506 | ; |
508 | is->cmds_n = i + 1; | 507 | is->cmds_n = i + 1; |
509 | is->commands = GNUNET_new_array (is->cmds_n, | 508 | is->commands = GNUNET_new_array (is->cmds_n, |
@@ -521,6 +520,27 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | |||
521 | return is; | 520 | return is; |
522 | } | 521 | } |
523 | 522 | ||
523 | struct GNUNET_TESTING_Command | ||
524 | GNUNET_TESTING_command_new (void *cls, | ||
525 | const char *label, | ||
526 | GNUNET_TESTING_CommandRunRoutine run, | ||
527 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
528 | GNUNET_TESTING_CommandGetTraits traits, | ||
529 | struct GNUNET_TESTING_AsyncContext *ac) | ||
530 | { | ||
531 | struct GNUNET_TESTING_Command cmd = { | ||
532 | .cls = cls, | ||
533 | .run = run, | ||
534 | .ac = ac, | ||
535 | .cleanup = cleanup, | ||
536 | .traits = traits | ||
537 | }; | ||
538 | memset (&cmd, 0, sizeof (cmd)); | ||
539 | strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH); | ||
540 | |||
541 | return cmd; | ||
542 | |||
543 | } | ||
524 | 544 | ||
525 | /** | 545 | /** |
526 | * Closure for #loop_run(). | 546 | * Closure for #loop_run(). |
@@ -658,6 +678,7 @@ free_barrier_node_cb (void *cls, | |||
658 | node->node_number); | 678 | node->node_number); |
659 | } | 679 | } |
660 | GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node); | 680 | GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node); |
681 | return GNUNET_YES; | ||
661 | } | 682 | } |
662 | 683 | ||
663 | 684 | ||
@@ -708,7 +729,6 @@ free_barriers_cb (void *cls, | |||
708 | struct GNUNET_TESTING_Interpreter *is = cls; | 729 | struct GNUNET_TESTING_Interpreter *is = cls; |
709 | struct GNUNET_TESTING_Barrier *barrier = value; | 730 | struct GNUNET_TESTING_Barrier *barrier = value; |
710 | struct GNUNET_TESTING_Command *pos; | 731 | struct GNUNET_TESTING_Command *pos; |
711 | struct GNUNET_TESTING_NetjailNode *node; | ||
712 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; | 732 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; |
713 | 733 | ||
714 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); | 734 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); |
@@ -725,6 +745,7 @@ free_barriers_cb (void *cls, | |||
725 | GNUNET_free (pos); | 745 | GNUNET_free (pos); |
726 | } | 746 | } |
727 | GNUNET_free (barrier); | 747 | GNUNET_free (barrier); |
748 | return GNUNET_YES; | ||
728 | } | 749 | } |
729 | 750 | ||
730 | 751 | ||
@@ -756,7 +777,6 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, | |||
756 | struct GNUNET_HashCode hc; | 777 | struct GNUNET_HashCode hc; |
757 | struct GNUNET_ShortHashCode create_key; | 778 | struct GNUNET_ShortHashCode create_key; |
758 | struct GNUNET_TESTING_Barrier *barrier; | 779 | struct GNUNET_TESTING_Barrier *barrier; |
759 | unsigned int kx; | ||
760 | 780 | ||
761 | GNUNET_CRYPTO_hash (barrier_name, strlen(barrier_name), &hc); | 781 | GNUNET_CRYPTO_hash (barrier_name, strlen(barrier_name), &hc); |
762 | memcpy (&create_key, | 782 | memcpy (&create_key, |