@@ -37,7 +37,7 @@ JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 27
3737 * Type cast the debugger send buffer into a specific type.
3838 */
3939#define JERRY_DEBUGGER_SEND_BUFFER_AS (type , name_p ) \
40- type *name_p = (type *) (& JERRY_CONTEXT (debugger_send_buffer ))
40+ type *name_p = (type *) (JERRY_CONTEXT (debugger_send_buffer_payload_p ))
4141
4242/**
4343 * Type cast the debugger receive buffer into a specific type.
@@ -92,7 +92,9 @@ jerry_debugger_send_backtrace (uint8_t *recv_buffer_p) /**< pointer to the recei
9292
9393 vm_frame_ctx_t * frame_ctx_p = JERRY_CONTEXT (vm_top_context_p );
9494
95- uint32_t current_frame = 0 ;
95+ size_t current_frame = 0 ;
96+ const size_t max_frame_count = JERRY_DEBUGGER_SEND_MAX (jerry_debugger_frame_t );
97+ const size_t max_message_size = JERRY_DEBUGGER_SEND_SIZE (max_frame_count , jerry_debugger_frame_t );
9698
9799 while (frame_ctx_p != NULL && max_depth > 0 )
98100 {
@@ -102,9 +104,9 @@ jerry_debugger_send_backtrace (uint8_t *recv_buffer_p) /**< pointer to the recei
102104 continue ;
103105 }
104106
105- if (current_frame >= JERRY_DEBUGGER_SEND_MAX ( jerry_debugger_frame_t ) )
107+ if (current_frame >= max_frame_count )
106108 {
107- if (!jerry_debugger_send (sizeof ( jerry_debugger_send_backtrace_t ) ))
109+ if (!jerry_debugger_send (max_message_size ))
108110 {
109111 return ;
110112 }
@@ -533,7 +535,7 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer to the rece
533535 memcpy (& eval_size , eval_first_p -> eval_size , sizeof (uint32_t ));
534536 bool is_eval = (recv_buffer_p [0 ] == JERRY_DEBUGGER_EVAL );
535537
536- if (eval_size <= JERRY_DEBUGGER_MAX_RECEIVE_SIZE - sizeof (jerry_debugger_receive_eval_first_t ))
538+ if (eval_size <= JERRY_CONTEXT ( debugger_max_receive_size ) - sizeof (jerry_debugger_receive_eval_first_t ))
537539 {
538540 if (eval_size != message_size - sizeof (jerry_debugger_receive_eval_first_t ))
539541 {
@@ -590,8 +592,10 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer to the rece
590592 uint32_t client_source_size ;
591593 memcpy (& client_source_size , client_source_first_p -> code_size , sizeof (uint32_t ));
592594
593- if (client_source_size <= JERRY_DEBUGGER_MAX_RECEIVE_SIZE - sizeof (jerry_debugger_receive_client_source_first_t )
594- && client_source_size != message_size - sizeof (jerry_debugger_receive_client_source_first_t ))
595+ uint32_t header_size = sizeof (jerry_debugger_receive_client_source_first_t );
596+
597+ if (client_source_size <= JERRY_CONTEXT (debugger_max_receive_size ) - header_size
598+ && client_source_size != message_size - header_size )
595599 {
596600 jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Invalid message size\n" );
597601 jerry_debugger_close_connection ();
@@ -796,37 +800,42 @@ jerry_debugger_send_string (uint8_t message_type, /**< message type */
796800{
797801 JERRY_ASSERT (JERRY_CONTEXT (debugger_flags ) & JERRY_DEBUGGER_CONNECTED );
798802
799- const size_t max_fragment_len = JERRY_DEBUGGER_SEND_MAX (uint8_t );
803+ const size_t max_byte_count = JERRY_DEBUGGER_SEND_MAX (uint8_t );
804+ const size_t max_message_size = JERRY_DEBUGGER_SEND_SIZE (max_byte_count , uint8_t );
800805
801806 JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_string_t , message_string_p );
802807
803808 message_string_p -> type = message_type ;
804809
805- while ( string_length > max_fragment_len )
810+ if ( sub_type != JERRY_DEBUGGER_NO_SUBTYPE )
806811 {
807- memcpy (message_string_p -> string , string_p , max_fragment_len );
812+ string_length += 1 ;
813+ }
808814
809- if (!jerry_debugger_send (sizeof (jerry_debugger_send_string_t )))
815+ while (string_length > max_byte_count )
816+ {
817+ memcpy (message_string_p -> string , string_p , max_byte_count );
818+
819+ if (!jerry_debugger_send (max_message_size ))
810820 {
811821 return false;
812822 }
813823
814- string_length -= max_fragment_len ;
815- string_p += max_fragment_len ;
816- }
817-
818- if (sub_type != JERRY_DEBUGGER_NO_SUBTYPE )
819- {
820- string_length += 1 ;
824+ string_length -= max_byte_count ;
825+ string_p += max_byte_count ;
821826 }
822827
823828 message_string_p -> type = (uint8_t ) (message_type + 1 );
824829
825- memcpy (message_string_p -> string , string_p , string_length );
826830 if (sub_type != JERRY_DEBUGGER_NO_SUBTYPE )
827831 {
832+ memcpy (message_string_p -> string , string_p , string_length - 1 );
828833 message_string_p -> string [string_length - 1 ] = sub_type ;
829834 }
835+ else
836+ {
837+ memcpy (message_string_p -> string , string_p , string_length );
838+ }
830839
831840 return jerry_debugger_send (sizeof (jerry_debugger_send_type_t ) + string_length );
832841} /* jerry_debugger_send_string */
0 commit comments