Conversation
toddr
marked this pull request as ready for review
May 25, 2026 00:48
Member
|
@toddr-bot attempt to write a vulnerability test which shows this issue by failing prior to the fix. |
Use a single SvPV(*ssv, len) call for both allocation size and copy length, eliminating the TOCTOU mismatch between the separate SvCUR() (allocation) and SvPV() (copy) calls. The old code could overrun the buffer if SvPV triggered stringify magic that produced a longer string than SvCUR had measured. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
toddr-bot
force-pushed
the
koan.toddr.bot/fix-strcpy-toctou
branch
from
May 25, 2026 04:10
508fa03 to
d0c61d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace unsafe
strcpy()with length-boundedmemcpy()inXS_unpack_charPtrPtr().Why
The old code used separate
SvCUR(*ssv)andSvPV(*ssv, PL_na)calls for allocationand copy respectively. If
SvPV()triggers stringify magic that produces a longer stringthan
SvCUR()measured, thestrcpy()overflows the allocated buffer (TOCTOU mismatch).How
A single
SvPV(*ssv, len)call now captures both the string pointer and its lengthatomically. The copy uses
memcpy(s[x], p, len)with explicit NUL termination, so theallocation size and copy length are guaranteed to match.
Testing
Full test suite passes. The
t/24c14n.ttests exerciseXS_unpack_charPtrPtrthroughtoStringEC14Nwith namespace prefix lists. A deterministic PoC for the TOCTOU raceis not feasible from Perl — it requires the SV to mutate between two consecutive C calls
in the same thread.
SECURITY — TOCTOU buffer overflow in
XS_unpack_charPtrPtr():SvCUR()measuresallocation size, then a separate
SvPV()call copies into that buffer. Stringify magicbetween the two calls can produce a longer string, causing heap overflow. This may warrant
a vulnerability report.
🤖 Generated with Claude Code
Quality Report
Changes: 1 file changed, 8 insertions(+), 3 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline