Skip to content

fix(rrd): require a terminated status line when reading RRDtool pipe replies - #8659

Open
somethingwithproof wants to merge 6 commits into
developfrom
fix/rrd-pipe-reply-anchor
Open

somethingwithproof wants to merge 6 commits into
developfrom
fix/rrd-pipe-reply-anchor

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

On the persistent RRDtool pipe, the end-of-reply check (lib/rrd.php) was not anchored: output ending in text such as PRINT:BOOK, or a PNG whose bytes happen to contain OK, was taken as a finished reply, and the rest of the output was then read as the next command's reply.

RRDtool ends every reply with OK u:%1.2f s:%1.2f r:%1.2f\n (or OK\n without getrusage) or with ERROR: ...\n, and for PNG output OK u: follows the last image byte with no newline before it, so anchoring OK to a line start would break PNG graphs. The check now requires the status to end with a newline, rejects OK only when a printable character comes right before it, and requires ERROR: to start a line.

Verification: two scripted fake-rrdtool cases (a PRINT:BOOK reply followed by a failing command, and OK inside partial PNG data) fail before the fix; a third test drives real RRDtool 1.11 through create, update, a PNG graph with PRINT text, last and a rejected update on one pipe. fake_rrdtool_argv.sh now ends text output with a newline like real RRDtool. RRD and Boost Pest suites 366 passed; PHPStan clean.

Native Windows validation: 14 parser cases pass on both PHP 8.3 and 8.4 with RRDtool 1.11.0. The real persistent-process test times out on both the PR and the exact develop base, tracked in #8776. Windows compatibility remains blocked. Run and base control.

Ref #8776

Merge order: this PR and #8828 change tests/Unit/RrdProcessSafetyTest.php. Suggested order: this PR, then #8828. Whichever merges later will be rebased.

@somethingwithproof
somethingwithproof requested a review from a team as a code owner November 8, 2026 21:25
@somethingwithproof
somethingwithproof requested review from TheWitness and removed request for a team November 8, 2026 21:25
@somethingwithproof
somethingwithproof force-pushed the fix/rrd-pipe-reply-anchor branch from b2294da to 3d697e7 Compare November 9, 2026 05:24
@github-actions
github-actions Bot force-pushed the fix/rrd-pipe-reply-anchor branch 4 times, most recently from cad1277 to 24f5f18 Compare November 11, 2026 21:06
@somethingwithproof somethingwithproof added this to the v1.3.0 milestone Nov 13, 2026
@somethingwithproof somethingwithproof added bug Undesired behaviour data collection Issues related to data collection labels Nov 13, 2026
@github-actions
github-actions Bot force-pushed the fix/rrd-pipe-reply-anchor branch 4 times, most recently from d303a0c to b604c7e Compare November 17, 2026 08:47
@somethingwithproof somethingwithproof added the release:1.3 Namespaced Cacti workflow label label Nov 17, 2026

@TheWitness TheWitness left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be tested on Windows?

@github-actions
github-actions Bot force-pushed the fix/rrd-pipe-reply-anchor branch from b604c7e to 2a19de5 Compare November 17, 2026 20:46
@somethingwithproof

Copy link
Copy Markdown
Member Author

Can this be tested on Windows?

Partly, in b2f38d5. The end-of-reply check is now rrdtool_reply_status(), and a new test exercises it on every platform with no shell stand-in. It covers what a native Windows RRDtool sends: stdout is in binary mode there, so lines end in LF, and the MSVC build has no getrusage, so the status is a bare OK. CRLF endings and partial replies are covered too. The two tests that drive a scripted RRDtool still need a POSIX shell and skip on Windows, and I haven't run the real-binary integration test on a Windows host. If you have one with RRDtool, a run of tests/integration/RrdtoolProcessIntegrationTest.php would settle it.

@somethingwithproof

Copy link
Copy Markdown
Member Author

Native Windows results are now available from windows-2022 hosts with PHP 8.3.36/8.4.27 and the native UCRT64 RRDtool 1.11.0 executable. All 14 parser cases pass on each host. The real persistent-process test stalls and hits its three-minute watchdog on both versions.

The same test also times out when only lib/rrd.php is replaced with the exact develop base (9235426). That establishes that the stall occurs without this parser change; it still blocks a Windows compatibility claim. Tracked as #8776, with the base control and logs: https://github.com/Cacti/cacti/actions/runs/44276696859

Linux Docker validation passed 58 process-safety tests (101 assertions) and five real-process integration tests (36 assertions). This PR remains blocked on the native Windows process-reader issue.

@github-actions
github-actions Bot force-pushed the fix/rrd-pipe-reply-anchor branch from 1630f27 to 5d4738b Compare November 25, 2026 20:48
The persistent RRDtool pipe treated any read whose tail was "OK" or
"ERROR:..." as the end of a reply, with no line anchor and no trailing
newline. A read that stopped after PRINT text such as "BOOK", or inside
image bytes that spell "OK", ended the reply early. The real status line
was then read as the next command's reply, so every later command on that
pipe was answered one step behind and a rejected update could be counted
as written.

Wait for RRDtool's actual terminator: a newline-terminated "OK u:..." (or
bare "OK" on builds without getrusage) that is not preceded by a printable
character, or an "ERROR:" line that starts a line. OK still matches
directly after binary image data, which RRDtool writes with no newline
before the status.

The pipe-pressure test double now newline-terminates its text output the
way RRDtool does.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The reply framing tests drove a /bin/sh double and were skipped on
Windows. Move the status-line check into rrdtool_reply_status() so the
framing decision itself is tested on every platform, including the reply
shapes a native Windows build produces: binary-mode stdout ending in LF
and a bare "OK" status, since that build has no getrusage. CRLF endings
are covered as well.

The matching rule is unchanged.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@github-actions
github-actions Bot force-pushed the fix/rrd-pipe-reply-anchor branch from 5d4738b to af45d3c Compare November 26, 2026 08:49
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

bug Undesired behaviour data collection Issues related to data collection release:1.3 Namespaced Cacti workflow label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants