diff options
Diffstat (limited to 'modules/core/module-fs.js')
| -rw-r--r-- | modules/core/module-fs.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/core/module-fs.js b/modules/core/module-fs.js index fd1dfc1..415bd92 100644 --- a/modules/core/module-fs.js +++ b/modules/core/module-fs.js @@ -238,7 +238,16 @@ class FileSystemModule { } const pattern = args[ai]; const target = args[ai + 1]; if (!pattern) return this.terminal.print('Usage: grep [-n] [-i] [-c] [-l] <pattern> [filename]', 'warning'); - const re = new RegExp(pattern, opt.ignoreCase ? 'i' : ''); + // v4.6.64: an invalid pattern is user input, not a system fault. It used to throw + // out of the command handler into the error ledger, polluting the counter that + // packet §2 says nobody can trust (packet §8). + let re; + try { + re = new RegExp(pattern, opt.ignoreCase ? 'i' : ''); + } catch (e) { + this.terminal.print('grep: invalid pattern: ' + pattern + ' (' + e.message + ')', 'warning'); + return; + } const hits = (line) => (opt.invert ? !re.test(line) : re.test(line)); if (target) { const c = this.terminal.fs.readFile(target); |