aboutsummaryrefslogtreecommitdiff
path: root/modules/core/terminal.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-10-23 15:55:51 +0200
committerAgando <roduccomm@gmail.com>2026-10-23 15:55:51 +0200
commit8d00c6949d19338e949618ddae4f1aef592cf58b (patch)
tree635ec4466ac23fdf15623cb2d066a1a3838ee5e5 /modules/core/terminal.js
parent921e7bada5703eb3a5058e8d0f89dffa44b82efc (diff)
fix(newos4): empty-pipeline crash, stacks in reports, frame in digest + dashboard (v4.6.55)
Root cause: splitPipe() splits on every '|', so `help |`, `| wc -l`, `a || b` produced a stage with no argv and executePipeChain() called parts[0].toLowerCase() on undefined — 989 occurrences, first filed 2026-10-20, unfixable from the report because bug reports dropped the stack that named executePipeChain:3955. Same unguarded read existed in _classify(). - terminal.js: _classify() returns an inert classification for empty argv; executePipeChain() parses each stage once, filters stages with no argv (so the last real stage stays final), warns only when the whole pipeline is empty. Last-stage test now compares against the filtered length. - module-system.js: `bug` diagnostics include the stack (10 frames, 1200 chars); auto-filed reports carry it too — they are the majority of the inbox and were previously message-only. - report.php: per-stack 2 KB cap; fingerprint pinned to message/source/count so adding `stack` cannot break dedupe against reports filed before today. - ingest.php: first_frame() parsed once on ingest, stored as `frame` on each signature. - newos4-triage.py: FRAME| line with the first application frame. - dashboard.php: frame under each Top Errors row. - modules/test/test-pipe-guard.js: ordering tripwire (guard must precede the parts[0] read). Verified: test RED exit=1 -> GREEN exit=0; browser matrix on v4.6.55 (help |, | wc -l, echo hi || echo bye, ls | | wc -l, |) -> 0 new error signatures, "|" warns; auto-filed report now carries stack (RPT-...f3e31124, archived after the probe); frame = modules/core/core-bundle.js:3955:42; maintain OK; skill audit 7/7.
Diffstat (limited to 'modules/core/terminal.js')
-rw-r--r--modules/core/terminal.js36
1 files changed, 29 insertions, 7 deletions
diff --git a/modules/core/terminal.js b/modules/core/terminal.js
index c586538..ad4b105 100644
--- a/modules/core/terminal.js
+++ b/modules/core/terminal.js
@@ -157,7 +157,14 @@
return args;
}
_classify(raw) {
- const parts = this._parseArgs(raw.trim());
+ const parts = this._parseArgs(String(raw || '').trim());
+ // `help |` and `| wc -l` produce an empty pipeline stage; parts[0] was undefined
+ // and every such invocation threw TypeError from this line (989 occurrences,
+ // first filed 2026-10-20). Classify the empty command as inert instead.
+ if (!parts.length) {
+ return { cmd: '', args: [], known: true, destructive: false, system: false,
+ unknown: false, hasSuspicious: false };
+ }
const cmd = parts[0].toLowerCase();
const args = parts.slice(1);
// Internal commands always allowed at terminal level, but security still classifies
@@ -1532,12 +1539,27 @@
return parts;
}
async executePipeChain(pipeParts) {
+ // Parse every stage once, then drop the ones with no argv. `help |` splits to
+ // ['help',''], `help | ""` to ['help',''] and `| wc -l` to ['','wc -l'] — all three
+ // produced an empty argv whose parts[0] was undefined and threw TypeError from
+ // parts[0].toLowerCase() (989 occurrences, first filed 2026-10-20). Filtering on
+ // argv (not just the string) also keeps the LAST real stage final, so its output is
+ // never swallowed by a trailing empty segment.
+ const stages = pipeParts
+ .map(t => this.security._parseArgs(String(t || '').trim()))
+ .filter(argv => argv.length > 0);
+ if (!stages.length) {
+ this.print('⚠️ Empty pipeline — nothing to run', 'warning');
+ return;
+ }
let pipeInput = null;
- for (let i = 0; i < pipeParts.length; i++) {
- const cmdText = pipeParts[i];
- const parts = this.security._parseArgs(cmdText);
- const cmd = parts[0].toLowerCase();
- const args = parts.slice(1);
+ for (let i = 0; i < stages.length; i++) {
+ const argv = stages[i];
+ const cmd = argv[0].toLowerCase();
+ const args = argv.slice(1);
+ // Rebuilt from argv so the security classifier sees the same tokenisation the
+ // dispatcher will use (quotes already stripped by _parseArgs).
+ const cmdText = argv.join(' ');
// v4.5.67: Security gate for pipe stages — was completely bypassed
const cls = this.security._classify(cmdText);
if (cls.destructive && this.security.level > 0) {
@@ -1553,7 +1575,7 @@
return;
}
this._pipeInput = pipeInput;
- if (i < pipeParts.length - 1) {
+ if (i < stages.length - 1) {
pipeInput = await this.capturePipeOutput(cmd, args);
} else {
await this.dispatchCommand(cmd, args);