Skip to content

Fix potential OoB in describe_scripted_caller - #843

Merged
jschwe merged 4 commits into
servo:mainfrom
jschwe:fix_ub
Nov 1, 2026
Merged

jschwe merged 4 commits into
servo:mainfrom
jschwe:fix_ub

Conversation

@jschwe

@jschwe jschwe commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

The fixed stack size in combination with strncpy, which does not null-terminate if the string is >= buffer length, CStr::from_ptr would read beyond the array bounds (until null is encountered). Fix this by using the existing fill string callback, to write directly into a rust allocated String.
Addtionally also harden the fill string callback, and convert to utf-8 lossy, instead of having UB if the SM side calls the callback with non-utf8 input.

Testing: No tests were added
Fixes: #839

The fixed stack size in combination with `strncpy`, which
does not null-terminate if the string is >= buffer length,
CStr::from_ptr would read beyond the array bounds (until null is encountered).
Fix this by using the existing fill string callback, to write directly
into a rust allocated String.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Avoid UB on non-utf8 inputs.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
@jschwe
jschwe enabled auto-merge (squash) November 1, 2026 16:03
@jschwe
jschwe merged commit 138c947 into servo:main Nov 1, 2026
87 of 89 checks passed
@jschwe
jschwe deleted the fix_ub branch November 1, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential Read out of bounds in describe_scripted_caller

2 participants