Skip to content

vm: bound trace data printing#10301

Open
fallintoplace wants to merge 2 commits into
firedancer-io:mainfrom
fallintoplace:fix/vm-trace-print-buffer
Open

vm: bound trace data printing#10301
fallintoplace wants to merge 2 commits into
firedancer-io:mainfrom
fallintoplace:fix/vm-trace-print-buffer

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

  • replace unbounded VM trace string appends with checked vsnprintf-backed helpers
  • cap printed memory event data at the existing 2048-byte stack buffer contract
  • add a large trace-data print regression case with event_data_max greater than 2048

Root cause

fd_vm_trace_printf() sized its stack buffer for 2048 printable data bytes, but data_sz came from trace->event_data_max. A larger trace data cap let the memory dump loop write past the buffer through unbounded fd_cstr_append_printf() / vsprintf calls.

Validation

  • git diff --check
  • clang -std=c17 -fsyntax-only -I. -D_XOPEN_SOURCE=700 -DFD_HAS_HOSTED=1 -DFD_HAS_INT128=1 -DFD_HAS_DOUBLE=1 -DFD_HAS_ALLOCA=1 src/flamenco/vm/fd_vm_trace.c
  • clang -std=c17 -fsyntax-only -I. -D_XOPEN_SOURCE=700 -DFD_HAS_HOSTED=1 -DFD_HAS_INT128=1 -DFD_HAS_DOUBLE=1 -DFD_HAS_ALLOCA=1 src/flamenco/vm/test_vm_base.c

Could not run gmake -j test_vm_base locally on macOS: the native make path hits BSD grep -P and does not expose a test_vm_base target in this environment.

@greptile-jt

greptile-jt Bot commented Jun 19, 2026

Copy link
Copy Markdown
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/flamenco/vm/fd_vm_trace.c
Line: 11-15

Comment:
**Missing format attribute for compile-time checking**

`fd_cstr_append_printf` in this codebase declares `__attribute__((format(printf,2,3)))` to enable compile-time format string validation (see `fd_cstr.h:240`). This new variadic helper should do the same to catch format/argument mismatches at compile time.

```suggestion
static int
fd_vm_trace_printf_append( char **      p,
                           char *       end,
                           char const * fmt,
                           ... ) __attribute__((format(printf,3,4)));
static int
fd_vm_trace_printf_append( char **      p,
                           char *       end,
                           char const * fmt,
                           ... ) {
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "vm: bound trace data printing" | Re-trigger Greptile

Comment on lines +11 to +15
static int
fd_vm_trace_printf_append( char ** p,
char * end,
char const * fmt,
... ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing format attribute for compile-time checking

fd_cstr_append_printf in this codebase declares __attribute__((format(printf,2,3))) to enable compile-time format string validation (see fd_cstr.h:240). This new variadic helper should do the same to catch format/argument mismatches at compile time.

Suggested change
static int
fd_vm_trace_printf_append( char ** p,
char * end,
char const * fmt,
... ) {
static int
fd_vm_trace_printf_append( char ** p,
char * end,
char const * fmt,
... ) __attribute__((format(printf,3,4)));
static int
fd_vm_trace_printf_append( char ** p,
char * end,
char const * fmt,
... ) {
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/flamenco/vm/fd_vm_trace.c
Line: 11-15

Comment:
**Missing format attribute for compile-time checking**

`fd_cstr_append_printf` in this codebase declares `__attribute__((format(printf,2,3)))` to enable compile-time format string validation (see `fd_cstr.h:240`). This new variadic helper should do the same to catch format/argument mismatches at compile time.

```suggestion
static int
fd_vm_trace_printf_append( char **      p,
                           char *       end,
                           char const * fmt,
                           ... ) __attribute__((format(printf,3,4)));
static int
fd_vm_trace_printf_append( char **      p,
                           char *       end,
                           char const * fmt,
                           ... ) {
```

How can I resolve this? If you propose a fix, please make it concise.

@greptile-jt

greptile-jt Bot commented Jun 19, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "vm: add trace printf format checking" | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant