rizin icon indicating copy to clipboard operation
rizin copied to clipboard

Fix parsing of GDB <reg> tags not separated by whitespace

Open raphaelr opened this issue 1 year ago • 1 comments

Your checklist for this pull request

  • [x] I've read the guidelines for contributing to this repository
  • [x] I made sure to follow the project's coding style
  • [ ] I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • [ ] I've added tests that prove my fix is effective or that my feature works (if possible)
  • [ ] I've updated the rizin book with the relevant information (if needed)

Detailed description

regstr_end + 3 would advance into the next <reg> tag if there is no whitespace between the two tags. This would cause the latter register to be ignored by the parser. Such an XML is for example used by mGBA's GDB stub.

Test plan

In one terminal:

$ gdbserver localhost:2345 ls

In another terminal:

$ rizin -c dr -D gdb gdb://localhost:2345

Verify that the register list is complete for your architecture.

For testing with mGBA, which generates the problematic XML:

  1. Run the emulator and load any rom (free homebrew roms are available)
  2. Click Tools -> Start GDB server
  3. Click Start
  4. Run rizin -c dr -D gdb gdb://localhost:2345
  5. Verify that the register list is complete: r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, sp, lr, pc, cpsr (currently in the dev branch, the odd-numbered registers are omitted)

raphaelr avatar Feb 19 '24 16:02 raphaelr

this patch feels wrong. probably we should use one of the rz_str_* methods.

wargio avatar Feb 21 '24 15:02 wargio