Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion php.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ char *php_readpipe(int php_process, char *command) {
break;
}

if (bptr >= result_string+BUFSIZE) {
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);
}
Comment on lines +275 to 278
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.

Expand Down
Loading