How many echoes may one ping ask for? (#1379) #1380

Merged
jaylouisw merged 1 commit from feat/ping-count into main 2026-11-10 20:26:45 +00:00
Owner

How many echoes may one ping ask for? Fixes #1379.

A count is a loop bound, and three surfaces took it from whoever asked:

  • engine/simulator.js ping() — opts.count || 4, then a loop. Measured: 5000 echoes in 23 ms, so 1e9
    echoes is roughly 4,600 seconds of engine time and a response nobody can hold. count: -5 produced zero
    replies and count: 'abc' produced an empty answer that reads like a dead network — neither is a count, and
    neither was questioned.
  • POST /ping — passed the number straight through, so all of the above was one unauthenticated request away.
  • web/app.js — parseInt(...) || 4. The field carries min=1 max=50, but a browser does not clamp a typed
    value, so 9999 was sent and 9999 replies drawn.

Same shape as the port-count ceiling (#1319): a number that bounds work, guarded at one door and not the others.

One rule, applied at each door

  • Simulator.ping() clamps to 50 (default 4), floors a fraction, falls back to 4 for anything that is not a
    count, and reports both count (what was sent) and requestedCount (what was asked for, null when nothing was
    asked) — so a clamp is visible instead of silent.
  • POST /ping answers 400 E_BAD_COUNT naming the range for anything that is not a whole number 1..50; an
    explicit null is treated as no count at all; the 200 body now carries count.
  • The console refuses ping <addr> 51 with the range, and ping <addr> 0 no longer silently sends four.
  • The dialog checks the field before sending, and says the same thing.

Two parser defects fell out of writing that

  • A stray word was ignored: ping 10.0.0.1 abc sent four echoes as if the word were not there. Now refused,
    with the usage line.
  • at took whatever followed it: ping 10.0.0.1 5 at later evaluated to NaN and silently pinged at the wrong
    instant, and a bare at was dropped. Both are refused, naming the value.
r1> ping 10.0.0.1 51
% Count must be a whole number from 1 to 50 (asked for 51)
r1> ping 10.0.0.1 abc
% Unrecognized "abc" (ping <address|name> [<count 1-50>] [at <ms>])
r1> ping 10.0.0.1 5 at later
% Invalid instant: later

Evidence

test/ping-count.test.js — 39 checks: the engine sends 50 for a billion and reports both numbers, falls back
to four for 0/-5/'abc'/null/'', floors 1.9 to 1, and the reply list is exactly as long as the count it
reports; the console refuses 51, 0, 999999, a stray word and a bad instant, while at <ms> still works; the
dialog and the console refuse and accept the same table of values; and over HTTP 51/0/-1/1.5/'abc' are
400s naming the range, null is absent, 50 returns 50 replies with count: 50, and no count returns four.

  • reverting engine/simulator.js → 2 of 39
  • reverting engine/cli.js → 9 of 39
  • reverting server/index.js → 7 of 39
  • reverting web/app.js → 3 of 39

docs/CLI.md gains the ping syntax with the three refusals; docs/ARCHITECTURE.md gains the count contract.

Suite: 193 suites, 7,444 assertions, 0 failed. Syntax: 261 files, OK.

How many echoes may one ping ask for? Fixes #1379. A count is a loop bound, and three surfaces took it from whoever asked: * **`engine/simulator.js` `ping()`** — `opts.count || 4`, then a loop. Measured: **5000 echoes in 23 ms**, so `1e9` echoes is roughly **4,600 seconds** of engine time and a response nobody can hold. `count: -5` produced **zero** replies and `count: 'abc'` produced an empty answer that reads like a dead network — neither is a count, and neither was questioned. * **`POST /ping`** — passed the number straight through, so all of the above was one unauthenticated request away. * **`web/app.js`** — `parseInt(...) || 4`. The field carries `min=1 max=50`, but a browser does not clamp a typed value, so `9999` was sent and 9999 replies drawn. Same shape as the port-count ceiling (#1319): a number that bounds work, guarded at one door and not the others. ## One rule, applied at each door * `Simulator.ping()` **clamps to 50** (default 4), floors a fraction, falls back to 4 for anything that is not a count, and reports both `count` (what was sent) and `requestedCount` (what was asked for, `null` when nothing was asked) — so a clamp is visible instead of silent. * `POST /ping` answers **`400 E_BAD_COUNT`** naming the range for anything that is not a whole number 1..50; an explicit `null` is treated as no count at all; the 200 body now carries `count`. * The console refuses `ping <addr> 51` with the range, and `ping <addr> 0` no longer silently sends four. * The dialog checks the field before sending, and says the same thing. ## Two parser defects fell out of writing that * A **stray word was ignored**: `ping 10.0.0.1 abc` sent four echoes as if the word were not there. Now refused, with the usage line. * **`at` took whatever followed it**: `ping 10.0.0.1 5 at later` evaluated to `NaN` and silently pinged at the wrong instant, and a bare `at` was dropped. Both are refused, naming the value. ``` r1> ping 10.0.0.1 51 % Count must be a whole number from 1 to 50 (asked for 51) r1> ping 10.0.0.1 abc % Unrecognized "abc" (ping <address|name> [<count 1-50>] [at <ms>]) r1> ping 10.0.0.1 5 at later % Invalid instant: later ``` ## Evidence `test/ping-count.test.js` — **39 checks**: the engine sends 50 for a billion and **reports both numbers**, falls back to four for `0`/`-5`/`'abc'`/`null`/`''`, floors `1.9` to 1, and the reply list is exactly as long as the count it reports; the console refuses `51`, `0`, `999999`, a stray word and a bad instant, while `at <ms>` still works; the dialog and the console refuse and accept the same table of values; and over HTTP `51`/`0`/`-1`/`1.5`/`'abc'` are 400s naming the range, `null` is absent, `50` returns 50 replies with `count: 50`, and no count returns four. * reverting `engine/simulator.js` → 2 of 39 * reverting `engine/cli.js` → **9 of 39** * reverting `server/index.js` → **7 of 39** * reverting `web/app.js` → 3 of 39 `docs/CLI.md` gains the ping syntax with the three refusals; `docs/ARCHITECTURE.md` gains the count contract. Suite: **193 suites, 7,444 assertions, 0 failed**. Syntax: 261 files, OK.
How many echoes may one ping ask for? (#1379)
Some checks failed
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 11s
CI / Classify the change (pull_request) Successful in 15s
CI / Test (Node 18) (pull_request) Successful in 2m51s
CI / Test (Node 20) (pull_request) Successful in 2m25s
CI / Server smoke test (pull_request) Successful in 26s
CI / Docker build (pull_request) Successful in 1m8s
CI / Test (Node 22) (pull_request) Failing after 2m30s
8ee16f5095
A count is a loop bound, and three surfaces took it from whoever asked:

  engine/simulator.js ping()   `opts.count || 4`, then a loop. Measured: 5000 echoes in 23 ms, so 1e9 echoes
                               is roughly 4,600 seconds of engine time and a response nobody can hold. `-5`
                               produced ZERO replies and `'abc'` produced an empty answer that reads like a
                               dead network, because neither is a count and neither was questioned.
  POST /ping                   passed the number straight through, so all of the above was one
                               unauthenticated request away.
  web/app.js  dialog           `parseInt(...) || 4`. The field carries min=1 max=50, but a browser does not
                               clamp a typed value, so 9999 was sent and 9999 replies were drawn.

One rule - a whole number from 1 to 50 - applied at each door, and the engine no longer trusts its callers:

  - simulator.ping() clamps to 50 (default 4), floors a fraction, falls back to 4 for anything that is not a
    count, and reports both `count` (what was sent) and `requestedCount` (what was asked for, null when
    nothing was asked), so a clamp is visible instead of silent.
  - POST /ping answers 400 E_BAD_COUNT naming the range for anything that is not a whole number 1..50; an
    explicit null is treated as no count at all; the 200 body now carries `count`.
  - the console refuses `ping <addr> 51` with the range, and `ping <addr> 0` no longer silently sends four.
  - the dialog checks the field before sending and says the same thing.

Two parser defects fell out of writing that:
  - a stray word was ignored, so `ping 10.0.0.1 abc` sent four echoes as if the word were not there. It is
    now refused with the usage line.
  - `at` took whatever followed it: `ping 10.0.0.1 5 at later` evaluated to NaN and silently pinged at the
    wrong instant, and a bare `at` was dropped. Both are refused now, naming the value.

Evidence: test/ping-count.test.js, 39 checks - the engine sends 50 for a billion and reports both numbers,
falls back to four for 0/-5/'abc'/null/'', floors 1.9 to 1, and the reply list is exactly as long as the
count it reports; the console refuses 51, 0, 999999, a stray word and a bad instant, and `at <ms>` still
works; the dialog and the console refuse and accept the same table of values; and over HTTP, 51/0/-1/1.5/'abc'
are 400s naming the range, null is treated as absent, 50 returns 50 replies and reports count 50, and no
count returns four. Reverting engine/simulator.js fails 2 of 39, engine/cli.js 9, server/index.js 7,
web/app.js 3.

docs/CLI.md gains the ping syntax with the three refusals; docs/ARCHITECTURE.md gains the count contract.

Suite: 193 suites, 7,444 assertions, 0 failed. Syntax: 261 files, OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-10 20:26:42 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1380
No description provided.