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/include | |
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/include')
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 768298b48..0b4c05a59 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h | |||
@@ -40,6 +40,10 @@ | |||
40 | */ | 40 | */ |
41 | #define GNUNET_S(a) #a | 41 | #define GNUNET_S(a) #a |
42 | 42 | ||
43 | /** | ||
44 | * Maximum length of label in command | ||
45 | */ | ||
46 | #define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 | ||
43 | 47 | ||
44 | /* ********************* Helper functions ********************* */ | 48 | /* ********************* Helper functions ********************* */ |
45 | 49 | ||
@@ -93,6 +97,37 @@ struct GNUNET_TESTING_AsyncContext | |||
93 | enum GNUNET_GenericReturnValue finished; | 97 | enum GNUNET_GenericReturnValue finished; |
94 | }; | 98 | }; |
95 | 99 | ||
100 | typedef void | ||
101 | (*GNUNET_TESTING_CommandRunRoutine)(void *cls, | ||
102 | struct GNUNET_TESTING_Interpreter *is); | ||
103 | |||
104 | typedef void | ||
105 | (*GNUNET_TESTING_CommandCleanupRoutine)(void *cls); | ||
106 | |||
107 | typedef enum GNUNET_GenericReturnValue | ||
108 | (*GNUNET_TESTING_CommandGetTraits) (void *cls, | ||
109 | const void **ret, | ||
110 | const char *trait, | ||
111 | unsigned int index); | ||
112 | |||
113 | /** | ||
114 | * Create a new command | ||
115 | * | ||
116 | * @param cls the closure | ||
117 | * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH | ||
118 | * @param run the run routing | ||
119 | * @param cleanup the cleanup function | ||
120 | * @param traits the traits function (optional) | ||
121 | * @param the async context | ||
122 | * @return the command the function cannot fail | ||
123 | */ | ||
124 | struct GNUNET_TESTING_Command | ||
125 | GNUNET_TESTING_command_new (void *cls, | ||
126 | const char *label, | ||
127 | GNUNET_TESTING_CommandRunRoutine run, | ||
128 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
129 | GNUNET_TESTING_CommandGetTraits traits, | ||
130 | struct GNUNET_TESTING_AsyncContext *ac); | ||
96 | 131 | ||
97 | /** | 132 | /** |
98 | * A command to be run by the interpreter. | 133 | * A command to be run by the interpreter. |
@@ -119,7 +154,7 @@ struct GNUNET_TESTING_Command | |||
119 | /** | 154 | /** |
120 | * Label for the command. | 155 | * Label for the command. |
121 | */ | 156 | */ |
122 | char *label; | 157 | char label[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1]; |
123 | 158 | ||
124 | /** | 159 | /** |
125 | * Runs the command. Note that upon return, the interpreter | 160 | * Runs the command. Note that upon return, the interpreter |
@@ -136,9 +171,7 @@ struct GNUNET_TESTING_Command | |||
136 | * @param cls closure | 171 | * @param cls closure |
137 | * @param is interpreter state | 172 | * @param is interpreter state |
138 | */ | 173 | */ |
139 | void | 174 | GNUNET_TESTING_CommandRunRoutine run; |
140 | (*run)(void *cls, | ||
141 | struct GNUNET_TESTING_Interpreter *is); | ||
142 | 175 | ||
143 | /** | 176 | /** |
144 | * Pointer to the asynchronous context in the command's | 177 | * Pointer to the asynchronous context in the command's |
@@ -156,8 +189,7 @@ struct GNUNET_TESTING_Command | |||
156 | * | 189 | * |
157 | * @param cls closure | 190 | * @param cls closure |
158 | */ | 191 | */ |
159 | void | 192 | GNUNET_TESTING_CommandCleanupRoutine cleanup; |
160 | (*cleanup)(void *cls); | ||
161 | 193 | ||
162 | /** | 194 | /** |
163 | * Extract information from a command that is useful for other | 195 | * Extract information from a command that is useful for other |
@@ -170,11 +202,7 @@ struct GNUNET_TESTING_Command | |||
170 | * @return #GNUNET_OK on success, | 202 | * @return #GNUNET_OK on success, |
171 | * #GNUNET_NO if no trait was found | 203 | * #GNUNET_NO if no trait was found |
172 | */ | 204 | */ |
173 | enum GNUNET_GenericReturnValue | 205 | GNUNET_TESTING_CommandGetTraits traits; |
174 | (*traits)(void *cls, | ||
175 | const void **ret, | ||
176 | const char *trait, | ||
177 | unsigned int index); | ||
178 | 206 | ||
179 | /** | 207 | /** |
180 | * When did the execution of this command start? | 208 | * When did the execution of this command start? |
@@ -377,7 +405,7 @@ typedef void | |||
377 | * @return The interpreter. | 405 | * @return The interpreter. |
378 | */ | 406 | */ |
379 | struct GNUNET_TESTING_Interpreter * | 407 | struct GNUNET_TESTING_Interpreter * |
380 | GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | 408 | GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, |
381 | struct GNUNET_TIME_Relative timeout, | 409 | struct GNUNET_TIME_Relative timeout, |
382 | GNUNET_TESTING_ResultCallback rc, | 410 | GNUNET_TESTING_ResultCallback rc, |
383 | void *rc_cls); | 411 | void *rc_cls); |
@@ -660,11 +688,11 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | |||
660 | */ | 688 | */ |
661 | #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \ | 689 | #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \ |
662 | enum GNUNET_GenericReturnValue \ | 690 | enum GNUNET_GenericReturnValue \ |
663 | GNUNET_TESTING_get_trait_ ## name ( \ | 691 | GNUNET_TESTING_get_trait_ ## name ( \ |
664 | const struct GNUNET_TESTING_Command *cmd, \ | 692 | const struct GNUNET_TESTING_Command *cmd, \ |
665 | type **ret); \ | 693 | type **ret); \ |
666 | struct GNUNET_TESTING_Trait \ | 694 | struct GNUNET_TESTING_Trait \ |
667 | GNUNET_TESTING_make_trait_ ## name ( \ | 695 | GNUNET_TESTING_make_trait_ ## name ( \ |
668 | type * value); | 696 | type * value); |
669 | 697 | ||
670 | 698 | ||
@@ -674,9 +702,9 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | |||
674 | */ | 702 | */ |
675 | #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ | 703 | #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ |
676 | enum GNUNET_GenericReturnValue \ | 704 | enum GNUNET_GenericReturnValue \ |
677 | GNUNET_TESTING_get_trait_ ## name ( \ | 705 | GNUNET_TESTING_get_trait_ ## name ( \ |
678 | const struct GNUNET_TESTING_Command *cmd, \ | 706 | const struct GNUNET_TESTING_Command *cmd, \ |
679 | type **ret) \ | 707 | type * *ret) \ |
680 | { \ | 708 | { \ |
681 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | 709 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ |
682 | return cmd->traits (cmd->cls, \ | 710 | return cmd->traits (cmd->cls, \ |
@@ -685,7 +713,7 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | |||
685 | 0); \ | 713 | 0); \ |
686 | } \ | 714 | } \ |
687 | struct GNUNET_TESTING_Trait \ | 715 | struct GNUNET_TESTING_Trait \ |
688 | GNUNET_TESTING_make_trait_ ## name ( \ | 716 | GNUNET_TESTING_make_trait_ ## name ( \ |
689 | type * value) \ | 717 | type * value) \ |
690 | { \ | 718 | { \ |
691 | struct GNUNET_TESTING_Trait ret = { \ | 719 | struct GNUNET_TESTING_Trait ret = { \ |
@@ -702,14 +730,14 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | |||
702 | */ | 730 | */ |
703 | #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \ | 731 | #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \ |
704 | enum GNUNET_GenericReturnValue \ | 732 | enum GNUNET_GenericReturnValue \ |
705 | GNUNET_TESTING_get_trait_ ## name ( \ | 733 | GNUNET_TESTING_get_trait_ ## name ( \ |
706 | const struct GNUNET_TESTING_Command *cmd, \ | 734 | const struct GNUNET_TESTING_Command *cmd, \ |
707 | unsigned int index, \ | 735 | unsigned int index, \ |
708 | type **ret); \ | 736 | type **ret); \ |
709 | struct GNUNET_TESTING_Trait \ | 737 | struct GNUNET_TESTING_Trait \ |
710 | GNUNET_TESTING_make_trait_ ## name ( \ | 738 | GNUNET_TESTING_make_trait_ ## name ( \ |
711 | unsigned int index, \ | 739 | unsigned int index, \ |
712 | type * value); | 740 | type *value); |
713 | 741 | ||
714 | 742 | ||
715 | /** | 743 | /** |
@@ -718,10 +746,10 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | |||
718 | */ | 746 | */ |
719 | #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \ | 747 | #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \ |
720 | enum GNUNET_GenericReturnValue \ | 748 | enum GNUNET_GenericReturnValue \ |
721 | GNUNET_TESTING_get_trait_ ## name ( \ | 749 | GNUNET_TESTING_get_trait_ ## name ( \ |
722 | const struct GNUNET_TESTING_Command *cmd, \ | 750 | const struct GNUNET_TESTING_Command *cmd, \ |
723 | unsigned int index, \ | 751 | unsigned int index, \ |
724 | type **ret) \ | 752 | type * *ret) \ |
725 | { \ | 753 | { \ |
726 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | 754 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ |
727 | return cmd->traits (cmd->cls, \ | 755 | return cmd->traits (cmd->cls, \ |
@@ -730,7 +758,7 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | |||
730 | index); \ | 758 | index); \ |
731 | } \ | 759 | } \ |
732 | struct GNUNET_TESTING_Trait \ | 760 | struct GNUNET_TESTING_Trait \ |
733 | GNUNET_TESTING_make_trait_ ## name ( \ | 761 | GNUNET_TESTING_make_trait_ ## name ( \ |
734 | unsigned int index, \ | 762 | unsigned int index, \ |
735 | type * value) \ | 763 | type * value) \ |
736 | { \ | 764 | { \ |