@@ -39,22 +39,29 @@ static void eip7251_plugin_init_contract(ethPluginInitContract_t *param) {
3939 eip7251_context_t * context = (eip7251_context_t * ) param -> pluginContext ;
4040
4141 explicit_bzero (context , sizeof (* context ));
42- memcpy (& context -> consolidation_request [context -> received ], param -> selector , SELECTOR_SIZE );
43- context -> received += SELECTOR_SIZE ;
44- param -> result = ETH_PLUGIN_RESULT_OK ;
42+ if ((context -> received + CALLDATA_SELECTOR_SIZE ) > sizeof (context -> consolidation_request )) {
43+ param -> result = ETH_PLUGIN_RESULT_ERROR ;
44+ } else {
45+ memcpy (& context -> consolidation_request [context -> received ],
46+ param -> selector ,
47+ CALLDATA_SELECTOR_SIZE );
48+ context -> received += CALLDATA_SELECTOR_SIZE ;
49+ param -> result = ETH_PLUGIN_RESULT_OK ;
50+ }
4551}
4652
4753static void eip7251_plugin_provider_parameter (ethPluginProvideParameter_t * param ) {
4854 eip7251_context_t * context = (eip7251_context_t * ) param -> pluginContext ;
4955
5056 if ((context -> received + param -> parameter_size ) > sizeof (context -> consolidation_request )) {
5157 param -> result = ETH_PLUGIN_RESULT_ERROR ;
58+ } else {
59+ memcpy (& context -> consolidation_request [context -> received ],
60+ param -> parameter ,
61+ param -> parameter_size );
62+ context -> received += param -> parameter_size ;
63+ param -> result = ETH_PLUGIN_RESULT_OK ;
5264 }
53- memcpy (& context -> consolidation_request [context -> received ],
54- param -> parameter ,
55- param -> parameter_size );
56- context -> received += param -> parameter_size ;
57- param -> result = ETH_PLUGIN_RESULT_OK ;
5865}
5966
6067static void eip7251_plugin_finalize (ethPluginFinalize_t * param ) {
@@ -80,50 +87,54 @@ static void eip7251_plugin_query_contract_id(ethQueryContractID_t *param) {
8087static void eip7251_plugin_query_contract_ui (ethQueryContractUI_t * param ) {
8188 eip7251_context_t * context = (eip7251_context_t * ) param -> pluginContext ;
8289
83- memcpy (param -> msg , "0x" , 2 );
84- switch (param -> screenIndex ) {
85- case 0 :
86- if (target_equals_source (context )) {
87- strlcpy (param -> title , "Validator" , param -> titleLength );
88- } else {
89- strlcpy (param -> title , "From validator" , param -> titleLength );
90- }
91- format_hex (context -> source_pubkey ,
92- sizeof (context -> source_pubkey ),
93- & param -> msg [2 ],
94- param -> msgLength - 2 );
95- break ;
96- case 1 :
97- strlcpy (param -> title , "To validator" , param -> titleLength );
98- format_hex (context -> target_pubkey ,
99- sizeof (context -> target_pubkey ),
100- & param -> msg [2 ],
101- param -> msgLength - 2 );
102- break ;
103- default :
104- break ;
90+ if (param -> msgLength >= 2 ) {
91+ memcpy (param -> msg , "0x" , 2 );
92+ switch (param -> screenIndex ) {
93+ case 0 :
94+ if (target_equals_source (context )) {
95+ strlcpy (param -> title , "Validator" , param -> titleLength );
96+ } else {
97+ strlcpy (param -> title , "From validator" , param -> titleLength );
98+ }
99+ format_hex (context -> source_pubkey ,
100+ sizeof (context -> source_pubkey ),
101+ & param -> msg [2 ],
102+ param -> msgLength - 2 );
103+ break ;
104+ case 1 :
105+ strlcpy (param -> title , "To validator" , param -> titleLength );
106+ format_hex (context -> target_pubkey ,
107+ sizeof (context -> target_pubkey ),
108+ & param -> msg [2 ],
109+ param -> msgLength - 2 );
110+ break ;
111+ default :
112+ break ;
113+ }
114+ param -> result = ETH_PLUGIN_RESULT_OK ;
105115 }
106- param -> result = ETH_PLUGIN_RESULT_OK ;
107116}
108117
109118void eip7251_plugin_call (eth_plugin_msg_t msg , void * param ) {
110- switch (msg ) {
111- case ETH_PLUGIN_INIT_CONTRACT :
112- eip7251_plugin_init_contract (param );
113- break ;
114- case ETH_PLUGIN_PROVIDE_PARAMETER :
115- eip7251_plugin_provider_parameter (param );
116- break ;
117- case ETH_PLUGIN_FINALIZE :
118- eip7251_plugin_finalize (param );
119- break ;
120- case ETH_PLUGIN_QUERY_CONTRACT_ID :
121- eip7251_plugin_query_contract_id (param );
122- break ;
123- case ETH_PLUGIN_QUERY_CONTRACT_UI :
124- eip7251_plugin_query_contract_ui (param );
125- break ;
126- default :
127- PRINTF ("Unhandled message 0x%x\n" , msg );
119+ if (param != NULL ) {
120+ switch (msg ) {
121+ case ETH_PLUGIN_INIT_CONTRACT :
122+ eip7251_plugin_init_contract (param );
123+ break ;
124+ case ETH_PLUGIN_PROVIDE_PARAMETER :
125+ eip7251_plugin_provider_parameter (param );
126+ break ;
127+ case ETH_PLUGIN_FINALIZE :
128+ eip7251_plugin_finalize (param );
129+ break ;
130+ case ETH_PLUGIN_QUERY_CONTRACT_ID :
131+ eip7251_plugin_query_contract_id (param );
132+ break ;
133+ case ETH_PLUGIN_QUERY_CONTRACT_UI :
134+ eip7251_plugin_query_contract_ui (param );
135+ break ;
136+ default :
137+ PRINTF ("Unhandled message 0x%x\n" , msg );
138+ }
128139 }
129140}
0 commit comments