Issue #301: Bug/Crash: Toolbar buffer overflow (Assertion failed) on wide terminal windows

Bug/Crash: Toolbar buffer overflow (Assertion failed) on wide terminal windows:

Describe the bug

When connecting to the Bus Pirate via a wide terminal emulator window (e.g., >200 columns), the device crashes, the USB connection drops, and dmesg shows enumeration errors (error -71).

I debugged this using a hardware probe (via OpenOCD/GDB in VS Code) and traced the crash to a hard assertion in tx_tb_start() inside src/usb_tx.c.

Root Cause Analysis

Image

In src/usb_tx.c, the toolbar buffer limit is defined as 1024:
#define MAXIMUM_TOOLBAR_BUFFER_BYTES 1024

However, when rendering the toolbar for a wide terminal (system_config.terminal_ansi_columns was 209 in my case), the combination of the text, ANSI color codes, and cursor hide/show escape sequences easily exceeds this limit.

During my GDB session, I caught the exact state right before the crash:

  • width = 209
  • buf_len = 1024
  • len reached 1032 inside toolbar_core1_service() (src/ui/ui_toolbar.c).

Because len (1032) > MAXIMUM_TOOLBAR_BUFFER_BYTES (1024), the following assertion is triggered, causing a panic on Core 1 and dropping the USB connection:
BP_ASSERT(len <= MAXIMUM_TOOLBAR_BUFFER_BYTES);

Steps to reproduce

  1. Connect Bus Pirate to the PC.
  2. Open a terminal emulator (i used tio) and maximize the window on a wide monitor (so terminal columns exceed ~200).
  3. The device attempts to render the bottom toolbar, hits the buffer limit, asserts, and crashes (USB disconnects).

Proposed Fix

The simplest fix is to increase the buffer size in src/usb_tx.c to accommodate modern wide displays.
Changing:
#define MAXIMUM_TOOLBAR_BUFFER_BYTES 1024
to:
#define MAXIMUM_TOOLBAR_BUFFER_BYTES 2048 (or 4096)
completely resolved the issue for me.

Alternatively, the rendering logic in toolbar_core1_service() could be modified to truncate the output if len approaches buf_len, preventing the overflow gracefully.

Environment

  • Hardware: RP2350 (Bus Pirate 6 / Custom Board)
  • Firmware: Main branch (latest)
  • OS: Linux (Ubuntu)

Issue opened by: reza-bakhshi

Thank you so much for the bug report!

I traced the root cause to an issue in ui_statusbar where it padded out the info line to full screen width, thus blowing the buffer limit. I clamped that to 80, which solves the immediate issue. The larger issue (snprintf error returns not handled correctly) will require a major rewrite, but the crash should be eliminated on large displays for now.

Image

The ā€˜i’ info command now shows the terminal size. Also, the width and length variables were updated to uint16 to accommodate wide terminals. Finally, the startup sequence no longer tries to set the terminal width to 80.

Bot-copy from GitHub comment by: DangerousPrototypes