mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 21:34:07 +08:00
libc/gdbstub: avoid RLE decoding special characters
Read/write special data like 0x2a2a2a2a will trigger this issue. The current GDB implementation has this flaw. GDB processes the RLE decoding before espaping the data, make it impossible to repeate special characters. The details can be seen in GDB source code remote.c remote_target::read_frame function. Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
@@ -58,6 +58,9 @@
|
||||
#define REPBIAS 29
|
||||
#define REPSIZE (255 - REPBIAS)
|
||||
|
||||
#define IS_SPECIAL_CHARACTERS(c) \
|
||||
((c) == '#' || (c) == '$' || (c) == '}' || (c) == '*')
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@@ -313,7 +316,7 @@ static int gdb_putchar(FAR struct gdb_state_s *state, int ch,
|
||||
static void gdb_escapechar(FAR struct gdb_state_s *state, char c,
|
||||
FAR char *csum)
|
||||
{
|
||||
if (c == '#' || c == '$' || c == '}' || c == '*')
|
||||
if (IS_SPECIAL_CHARACTERS(c))
|
||||
{
|
||||
gdb_putchar(state, '}', csum);
|
||||
gdb_putchar(state, c ^ 0x20, csum); /* See https://sourceware.org/gdb/current/onlinedocs/gdb.html/Overview.html#Binary-Data */
|
||||
@@ -409,6 +412,19 @@ static int gdb_send_packet(FAR struct gdb_state_s *state)
|
||||
size_t count = gdb_count_repeat(&buf[i], len - i);
|
||||
|
||||
i += count;
|
||||
|
||||
/* GDB cannot process repeated special characters. */
|
||||
|
||||
if (IS_SPECIAL_CHARACTERS(c))
|
||||
{
|
||||
while (count--)
|
||||
{
|
||||
gdb_escapechar(state, c, &csum);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count <= 3)
|
||||
{
|
||||
while (count-- > 0)
|
||||
|
||||
Reference in New Issue
Block a user