@@ -94,6 +94,9 @@ static bool setTagValuePairs(bool displayNetwork, bool fromPlugin) {
9494 for (pairIndex = 0 ; pairIndex < dataContext .tokenContext .pluginUiMaxItems ; pairIndex ++ ) {
9595 // for the next dataContext.tokenContext.pluginUiMaxItems items, get tag/value from
9696 // plugin_ui_get_item_internal()
97+ if (nbPairs >= g_pairsList -> nbPairs ) {
98+ return false;
99+ }
97100 dataContext .tokenContext .pluginUiCurrentItem = pairIndex ;
98101 if (!plugin_ui_get_item_internal ((uint8_t * ) plugin_buffers [counter ].title ,
99102 TAG_MAX_LEN ,
@@ -216,8 +219,8 @@ static bool setTagValuePairs(bool displayNetwork, bool fromPlugin) {
216219 * transaction
217220 * @return The number of g_pairs to display
218221 */
219- static uint8_t getNbPairs (bool displayNetwork , bool fromPlugin ) {
220- uint8_t nbPairs = 0 ;
222+ static size_t getNbPairs (bool displayNetwork , bool fromPlugin ) {
223+ size_t nbPairs = 0 ;
221224
222225 // Setup data to display
223226 if (fromPlugin ) {
@@ -277,7 +280,7 @@ static uint8_t getNbPairs(bool displayNetwork, bool fromPlugin) {
277280static bool ux_init (bool fromPlugin , uint8_t title_len , uint8_t finish_len ) {
278281 uint64_t chain_id = 0 ;
279282 uint16_t buf_size = 0 ;
280- uint8_t nbPairs = 0 ;
283+ size_t nbPairs = 0 ;
281284 bool displayNetwork = false;
282285
283286 chain_id = get_tx_chain_id ();
@@ -287,9 +290,13 @@ static bool ux_init(bool fromPlugin, uint8_t title_len, uint8_t finish_len) {
287290 }
288291 // Compute the number of g_pairs to display
289292 nbPairs = getNbPairs (displayNetwork , fromPlugin );
293+ if (nbPairs > UINT8_MAX ) {
294+ PRINTF ("Error: Too many review pairs: %u\n" , (unsigned ) nbPairs );
295+ goto error ;
296+ }
290297
291298 // Initialize the buffers
292- if (!ui_pairs_init (nbPairs )) {
299+ if (!ui_pairs_init (( uint8_t ) nbPairs )) {
293300 // Initialization failed, cleanup and return
294301 goto error ;
295302 }
0 commit comments