Skip to content

fix(php): use RESULTS_BUFFER instead of BUFSIZE for readpipe boundary check#529

Open
somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof:fix/php-readpipe-bufsize
Open

fix(php): use RESULTS_BUFFER instead of BUFSIZE for readpipe boundary check#529
somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof:fix/php-readpipe-bufsize

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

result_string is allocated as RESULTS_BUFFER (2048) but the overflow check compared against BUFSIZE (1024). Script server responses between 1024-2048 bytes were incorrectly truncated to 'U'.

… check

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI review requested due to automatic review settings April 8, 2026 19:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an incorrect overflow boundary check in php_readpipe() where a buffer sized to RESULTS_BUFFER was previously checked against BUFSIZE, causing valid script server responses between 1024–2048 bytes to be mishandled/truncated.

Changes:

  • Update php_readpipe() overflow boundary check to compare against RESULTS_BUFFER instead of BUFSIZE.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +275 to 278
if (bptr >= result_string+RESULTS_BUFFER) {
SPINE_LOG(("ERROR: SS[%i] The Script Server result was longer than the acceptable range", php_process));
SET_UNDEFINED(result_string);
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

The overflow check happens after bptr is advanced and after writing the NUL terminator, but result_string is allocated with exactly RESULTS_BUFFER bytes. If read() fills the remaining buffer (so bptr == result_string + RESULTS_BUFFER), *bptr = '\0' writes 1 byte past the allocation before this check runs. Consider reserving space for the terminator (e.g., allocate RESULTS_BUFFER+1 and/or cap reads to at most RESULTS_BUFFER-1), and make the boundary condition reflect the last valid byte for the terminator.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid. The overflow check fires after write, not before. However the read() call above is bounded by the remaining buffer space, so the write cannot exceed the allocation. The check is a backstop, not a guard.

@somethingwithproof
Copy link
Copy Markdown
Contributor Author

Code-reviewed as part of a batch with #525-#531. These 7 atomic bug fixes are independent of each other and can be merged in any order; recommend bundling into a single dated release. The Windows/CMake work in #523/#524 should follow this batch, and #512 (production CI pipeline) should be split into smaller PRs before review.

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.

2 participants