nish 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -59
- package/docs/AI.md +56 -9
- package/docs/INSTALL.md +22 -10
- package/llms.txt +1 -1
- package/package.json +17 -5
- package/runtime/browser.d.ts +14 -0
- package/runtime/browser.mjs +88 -0
- package/runtime/core/arrays.d.ts +18 -0
- package/runtime/core/arrays.mjs +125 -0
- package/runtime/core/checks.mjs +20 -0
- package/runtime/core/host.d.ts +70 -0
- package/runtime/core/host.mjs +311 -0
- package/runtime/core/numbers.d.ts +53 -0
- package/runtime/core/numbers.mjs +316 -0
- package/runtime/core/result.d.ts +41 -0
- package/runtime/core/result.mjs +127 -0
- package/runtime/core/strings.d.ts +14 -0
- package/runtime/core/strings.mjs +169 -0
- package/runtime/core.d.ts +9 -0
- package/runtime/core.mjs +55 -0
- package/runtime/host.d.ts +6 -0
- package/runtime/nish.d.ts +44 -0
- package/runtime/nish.h +75 -2
- package/runtime/nish.mjs +23 -3
- package/runtime/node.mjs +383 -0
- package/runtime/runtime-bytes.c +401 -0
- package/runtime/runtime-cross.c +1 -1
- package/runtime/runtime-host.c +1 -1
- package/runtime/runtime-os.c +1 -1
- package/runtime/runtime-parallel.c +1 -1
- package/runtime/runtime-simd.c +231 -7
- package/runtime/runtime-term.c +504 -0
- package/runtime/runtime-wasm.c +0 -11
- package/runtime/runtime.c +190 -6
- package/runtime/shim.mjs +6 -985
- package/runtime/sqlite/LICENSE.md +85 -0
- package/runtime/sqlite/README.md +45 -0
- package/runtime/sqlite/nish-sqlite.c +359 -0
- package/runtime/sqlite/sqlite3.c +271131 -0
- package/runtime/sqlite/sqlite3.h +14447 -0
- package/scripts/build.sh +261 -53
- package/scripts/fuzz.sh +218 -0
- package/scripts/gen-json-pow5.mjs +130 -0
- package/scripts/platform-package.mjs +3 -1
- package/scripts/security-scope.mjs +139 -0
- package/scripts/smoke.sh +3 -2
- package/std/LICENSE-fast-float +23 -0
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +31 -11
- package/std/base64.ts +116 -0
- package/std/bytes.ts +256 -0
- package/std/cli.ts +328 -0
- package/std/collections.ts +6 -5
- package/std/crypto/LICENSE-crypt_blowfish +26 -0
- package/std/crypto/base64url.ts +125 -0
- package/std/crypto/bcrypt.ts +760 -0
- package/std/crypto/hmac.ts +138 -2
- package/std/crypto/x509.ts +11 -122
- package/std/json-tokenizer.ts +2998 -57
- package/std/json-value.ts +22 -3
- package/std/json.ts +83 -1
- package/std/math.ts +608 -0
- package/std/net/http1-server.ts +85 -8
- package/std/net/http3-server.ts +50 -12
- package/std/net/postgres.ts +1875 -0
- package/std/net/quic-listener.ts +20 -4
- package/std/regex.ts +4274 -0
- package/std/sqlite.ts +391 -0
- package/std/term-io.ts +978 -0
- package/std/term-pixels.ts +874 -0
- package/std/term-probe.ts +459 -0
- package/std/term-rate.ts +993 -0
- package/std/term.ts +2453 -0
- package/std/text.ts +90 -7
- package/std/yaml-lines.ts +141 -0
- package/std/yaml.ts +4675 -0
package/scripts/fuzz.sh
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Build, run and replay the libFuzzer targets in tests/fuzz/targets/.
|
|
3
|
+
#
|
|
4
|
+
# scripts/fuzz.sh --build <name> build/fuzz/bin/<name>
|
|
5
|
+
# scripts/fuzz.sh --run <name> [-- <libFuzzer args>]
|
|
6
|
+
# fuzz it, growing its corpus
|
|
7
|
+
# scripts/fuzz.sh --replay [<name>] every corpus and regression
|
|
8
|
+
# input once; a crash fails
|
|
9
|
+
# scripts/fuzz.sh --smoke every target: build, replay,
|
|
10
|
+
# then a short fixed-seed run
|
|
11
|
+
#
|
|
12
|
+
# A target is `tests/fuzz/targets/<name>.ts` exporting
|
|
13
|
+
# `export const fuzzOne = (data: u8[]): void` (tests/fuzz/README.md). It is
|
|
14
|
+
# compiled to a library .ll with the repository's compiler and std, and linked
|
|
15
|
+
# with tests/fuzz/harness.c and the runtime under
|
|
16
|
+
# `-fsanitize=fuzzer,address,undefined`, with the runtime built
|
|
17
|
+
# `-DNISH_FUZZ_ABORT` so a panic, a failed bounds or division check and an
|
|
18
|
+
# out-of-memory are crashes. The runtime units are linked from source, so a
|
|
19
|
+
# change to runtime/ needs nothing but a rebuild.
|
|
20
|
+
#
|
|
21
|
+
# Environment:
|
|
22
|
+
# NISH the compiler (default build/nish; `npm run build`). It
|
|
23
|
+
# must be one built from this checkout: a compiler finds
|
|
24
|
+
# std/ beside itself, so the seed would fuzz its own std.
|
|
25
|
+
# FUZZ_SMOKE_SECONDS --smoke's fuzzing time per target (default 20)
|
|
26
|
+
# FUZZ_SEED --smoke's libFuzzer -seed (default 1)
|
|
27
|
+
# FUZZ_OUT where binaries, scratch corpora and artifacts go
|
|
28
|
+
# (default build/fuzz)
|
|
29
|
+
#
|
|
30
|
+
# Every libFuzzer run is given `-timeout=1` (an input over a second is a crash,
|
|
31
|
+
# as the target interface says) and `-rss_limit_mb=2048`, before the caller's
|
|
32
|
+
# own arguments, which may override them.
|
|
33
|
+
set -euo pipefail
|
|
34
|
+
|
|
35
|
+
root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
36
|
+
cd "$root"
|
|
37
|
+
|
|
38
|
+
NISH="${NISH:-build/nish}"
|
|
39
|
+
FUZZ_OUT="${FUZZ_OUT:-build/fuzz}"
|
|
40
|
+
FUZZ_SMOKE_SECONDS="${FUZZ_SMOKE_SECONDS:-20}"
|
|
41
|
+
FUZZ_SEED="${FUZZ_SEED:-1}"
|
|
42
|
+
CC="${CC:-clang}"
|
|
43
|
+
|
|
44
|
+
# The runtime's C units: tests/run.js's RUNTIME_C, which its `fuzz` section
|
|
45
|
+
# checks this list against. runtime-wasm.c is wasm32's alone.
|
|
46
|
+
RUNTIME_C=(
|
|
47
|
+
runtime/runtime.c
|
|
48
|
+
runtime/runtime-os.c
|
|
49
|
+
runtime/runtime-parallel.c
|
|
50
|
+
runtime/runtime-cross.c
|
|
51
|
+
runtime/runtime-host.c
|
|
52
|
+
runtime/runtime-net.c
|
|
53
|
+
runtime/runtime-simd.c
|
|
54
|
+
runtime/runtime-aes.c
|
|
55
|
+
runtime/runtime-term.c
|
|
56
|
+
runtime/runtime-bytes.c
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
SAN_FLAGS=(-g -O1 "-fsanitize=fuzzer,address,undefined" -fno-sanitize-recover=undefined)
|
|
60
|
+
LIBFUZZER_DEFAULTS=(-timeout=1 -rss_limit_mb=2048)
|
|
61
|
+
|
|
62
|
+
die() {
|
|
63
|
+
echo "fuzz.sh: $*" >&2
|
|
64
|
+
exit 2
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
usage() {
|
|
68
|
+
sed -n '2,11p' "$0" | sed 's/^# \{0,1\}//' >&2
|
|
69
|
+
exit "${1:-2}"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
targets() {
|
|
73
|
+
local f
|
|
74
|
+
for f in tests/fuzz/targets/*.ts; do
|
|
75
|
+
[ -e "$f" ] || continue
|
|
76
|
+
basename "$f" .ts
|
|
77
|
+
done
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
need_target() {
|
|
81
|
+
[ -f "tests/fuzz/targets/$1.ts" ] || die "no target tests/fuzz/targets/$1.ts"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# The runtime objects, compiled once per invocation of this script: every
|
|
85
|
+
# target links the same ones.
|
|
86
|
+
runtime_objs=()
|
|
87
|
+
build_runtime() {
|
|
88
|
+
[ ${#runtime_objs[@]} -eq 0 ] || return 0
|
|
89
|
+
[ -x "$NISH" ] || die "no compiler at $NISH: run \`npm run build\`, or set NISH"
|
|
90
|
+
command -v "$CC" >/dev/null || die "no $CC on PATH"
|
|
91
|
+
mkdir -p "$FUZZ_OUT/obj"
|
|
92
|
+
local src obj
|
|
93
|
+
for src in "${RUNTIME_C[@]}"; do
|
|
94
|
+
obj="$FUZZ_OUT/obj/$(basename "$src" .c).o"
|
|
95
|
+
"$CC" "${SAN_FLAGS[@]}" -DNISH_FUZZ_ABORT -Iruntime -c "$src" -o "$obj" \
|
|
96
|
+
|| die "compiling $src under the sanitizers failed (is libclang-rt-18-dev installed?)"
|
|
97
|
+
runtime_objs+=("$obj")
|
|
98
|
+
done
|
|
99
|
+
"$CC" "${SAN_FLAGS[@]}" -DNISH_FUZZ_ABORT -Iruntime -c tests/fuzz/harness.c \
|
|
100
|
+
-o "$FUZZ_OUT/obj/harness.o"
|
|
101
|
+
runtime_objs+=("$FUZZ_OUT/obj/harness.o")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
build() {
|
|
105
|
+
local name="$1"
|
|
106
|
+
need_target "$name"
|
|
107
|
+
build_runtime
|
|
108
|
+
local ir="$FUZZ_OUT/ir/$name"
|
|
109
|
+
rm -rf "$ir"
|
|
110
|
+
mkdir -p "$ir" "$FUZZ_OUT/bin"
|
|
111
|
+
if ! "$NISH" "tests/fuzz/targets/$name.ts" -o "$ir/" >"$ir.log" 2>&1; then
|
|
112
|
+
cat "$ir.log" >&2
|
|
113
|
+
die "$name: compile failed"
|
|
114
|
+
fi
|
|
115
|
+
# clang instruments only functions carrying `sanitize_address`, which the
|
|
116
|
+
# compiler never emits, so every definition is given it here; without it the
|
|
117
|
+
# compiled Nish code links under ASan uninstrumented. Every `define` line
|
|
118
|
+
# ends `) {` or `) #N {` (an attribute group), and `#N sanitize_address` is a
|
|
119
|
+
# valid mixed list. UBSan instruments in clang's frontend, so it never
|
|
120
|
+
# reaches a .ll: the compiled code's own bounds and division checks stand
|
|
121
|
+
# in for it. A define this misses fails the build rather than going quiet.
|
|
122
|
+
sed -i -E 's/^(define .*\) (#[0-9]+ )?)\{$/\1sanitize_address {/' "$ir"/*.ll
|
|
123
|
+
if grep -h '^define ' "$ir"/*.ll | grep -qv ' sanitize_address {$'; then
|
|
124
|
+
die "$name: a define in $ir/ was not given sanitize_address"
|
|
125
|
+
fi
|
|
126
|
+
# A library build writes one module per source module, the std modules the
|
|
127
|
+
# target imports included, and the link takes them all.
|
|
128
|
+
"$CC" "${SAN_FLAGS[@]}" -Wno-override-module "$ir"/*.ll "${runtime_objs[@]}" -lm \
|
|
129
|
+
-o "$FUZZ_OUT/bin/$name" || die "$name: link failed"
|
|
130
|
+
echo "fuzz.sh: built $FUZZ_OUT/bin/$name"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# The directories of inputs a target is replayed over: its seed corpus and its
|
|
134
|
+
# regressions, those that exist.
|
|
135
|
+
input_dirs() {
|
|
136
|
+
local d
|
|
137
|
+
for d in "tests/fuzz/corpus/$1" "tests/fuzz/regressions/$1"; do
|
|
138
|
+
[ -d "$d" ] && echo "$d"
|
|
139
|
+
done
|
|
140
|
+
return 0
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
replay() {
|
|
144
|
+
local name="$1" dirs
|
|
145
|
+
mapfile -t dirs < <(input_dirs "$name")
|
|
146
|
+
if [ ${#dirs[@]} -eq 0 ]; then
|
|
147
|
+
die "$name: no tests/fuzz/corpus/$name/ to replay"
|
|
148
|
+
fi
|
|
149
|
+
mkdir -p "$FUZZ_OUT/artifacts/$name"
|
|
150
|
+
# -runs=0 runs each input once and fuzzes nothing; nothing is written to the
|
|
151
|
+
# corpus directories.
|
|
152
|
+
"$FUZZ_OUT/bin/$name" "${LIBFUZZER_DEFAULTS[@]}" -runs=0 \
|
|
153
|
+
-artifact_prefix="$FUZZ_OUT/artifacts/$name/" "${dirs[@]}"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
# Fuzz `name` with a scratch copy of its corpus as the first (written)
|
|
157
|
+
# directory, so the checked-in corpus only grows when someone copies inputs
|
|
158
|
+
# back by hand (tests/fuzz/README.md).
|
|
159
|
+
run() {
|
|
160
|
+
local name="$1"
|
|
161
|
+
shift
|
|
162
|
+
local work="$FUZZ_OUT/work/$name" dirs
|
|
163
|
+
mkdir -p "$work" "$FUZZ_OUT/artifacts/$name"
|
|
164
|
+
mapfile -t dirs < <(input_dirs "$name")
|
|
165
|
+
"$FUZZ_OUT/bin/$name" "${LIBFUZZER_DEFAULTS[@]}" \
|
|
166
|
+
-artifact_prefix="$FUZZ_OUT/artifacts/$name/" "$@" "$work" "${dirs[@]}"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
[ $# -ge 1 ] || usage
|
|
170
|
+
mode="$1"
|
|
171
|
+
shift
|
|
172
|
+
case "$mode" in
|
|
173
|
+
--build)
|
|
174
|
+
[ $# -eq 1 ] || usage
|
|
175
|
+
build "$1"
|
|
176
|
+
;;
|
|
177
|
+
--run)
|
|
178
|
+
[ $# -ge 1 ] || usage
|
|
179
|
+
name="$1"
|
|
180
|
+
shift
|
|
181
|
+
if [ $# -ge 1 ]; then
|
|
182
|
+
[ "$1" = "--" ] || usage
|
|
183
|
+
shift
|
|
184
|
+
fi
|
|
185
|
+
build "$name"
|
|
186
|
+
run "$name" "$@"
|
|
187
|
+
;;
|
|
188
|
+
--replay)
|
|
189
|
+
if [ $# -eq 1 ]; then
|
|
190
|
+
names=("$1")
|
|
191
|
+
else
|
|
192
|
+
[ $# -eq 0 ] || usage
|
|
193
|
+
mapfile -t names < <(targets)
|
|
194
|
+
fi
|
|
195
|
+
for name in "${names[@]}"; do
|
|
196
|
+
build "$name"
|
|
197
|
+
replay "$name"
|
|
198
|
+
done
|
|
199
|
+
;;
|
|
200
|
+
--smoke)
|
|
201
|
+
[ $# -eq 0 ] || usage
|
|
202
|
+
mapfile -t names < <(targets)
|
|
203
|
+
[ ${#names[@]} -gt 0 ] || die "no targets in tests/fuzz/targets/"
|
|
204
|
+
for name in "${names[@]}"; do
|
|
205
|
+
build "$name"
|
|
206
|
+
replay "$name"
|
|
207
|
+
rm -rf "$FUZZ_OUT/work/$name"
|
|
208
|
+
run "$name" -seed="$FUZZ_SEED" -max_total_time="$FUZZ_SMOKE_SECONDS" -print_final_stats=1
|
|
209
|
+
done
|
|
210
|
+
echo "fuzz.sh: smoke passed over ${#names[@]} targets"
|
|
211
|
+
;;
|
|
212
|
+
-h | --help)
|
|
213
|
+
usage 0
|
|
214
|
+
;;
|
|
215
|
+
*)
|
|
216
|
+
usage
|
|
217
|
+
;;
|
|
218
|
+
esac
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Generate the power-of-five table of `std/json-tokenizer.ts`.
|
|
4
|
+
*
|
|
5
|
+
* node scripts/gen-json-pow5.mjs rewrite the table in std/json-tokenizer.ts
|
|
6
|
+
* node scripts/gen-json-pow5.mjs --check exit 1 if the table there differs by a byte
|
|
7
|
+
*
|
|
8
|
+
* The table is the region of `json-tokenizer.ts` between the
|
|
9
|
+
* `gen-json-pow5:begin` and `gen-json-pow5:end` lines: `jsonTokPowerOfFive`,
|
|
10
|
+
* which answers the 128-bit truncation of 5^q for q from -342 to 308 as two
|
|
11
|
+
* 64-bit words, high first, so 1,302 words. For q ≥ 0 it is 5^q shifted left
|
|
12
|
+
* or right until its top bit is bit 127, truncated. For q < 0 it is
|
|
13
|
+
* 2^b / 5^-q rounded up, for the b that puts its top bit there; while 5^-q
|
|
14
|
+
* fits in 64 bits (q ≥ -27) that b is z + 127, with z the bit length of 5^-q,
|
|
15
|
+
* and past it the quotient of 2^(2z + 128) is halved down to 128 bits.
|
|
16
|
+
*
|
|
17
|
+
* This is fast_float's `script/table_generation.py`, at commit 0de7a21,
|
|
18
|
+
* written again with BigInt: the table is computed with exact integer
|
|
19
|
+
* arithmetic, so a reader can check it rather than trust a transcription. The
|
|
20
|
+
* region lives inside `json-tokenizer.ts` rather than in a module of its own
|
|
21
|
+
* because a file under `std/` is a public `nish/` module.
|
|
22
|
+
*
|
|
23
|
+
* Adapted from fast_float (https://github.com/fastfloat/fast_float),
|
|
24
|
+
* include/fast_float/decimal_to_binary.h and script/table_generation.py.
|
|
25
|
+
* Copyright 2021 The fast_float authors. Used under the Boost Software License,
|
|
26
|
+
* Version 1.0; see std/LICENSE-fast-float.
|
|
27
|
+
*/
|
|
28
|
+
import fs from "node:fs"
|
|
29
|
+
import path from "node:path"
|
|
30
|
+
import { fileURLToPath } from "node:url"
|
|
31
|
+
|
|
32
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
33
|
+
const target = path.join(root, "std", "json-tokenizer.ts")
|
|
34
|
+
|
|
35
|
+
/** `JSON_TOK_SMALLEST_POWER` and `JSON_TOK_LARGEST_POWER`. */
|
|
36
|
+
const SMALLEST = -342
|
|
37
|
+
const LARGEST = 308
|
|
38
|
+
|
|
39
|
+
const TOP = 1n << 127n
|
|
40
|
+
const LIMIT = 1n << 128n
|
|
41
|
+
const WORD = (1n << 64n) - 1n
|
|
42
|
+
|
|
43
|
+
/** The bit length of a positive BigInt. */
|
|
44
|
+
const bits = (n) => n.toString(2).length
|
|
45
|
+
|
|
46
|
+
const entries = []
|
|
47
|
+
for (let q = SMALLEST; q < 0; q++) {
|
|
48
|
+
const p = 5n ** BigInt(-q)
|
|
49
|
+
const z = BigInt(bits(p))
|
|
50
|
+
let c
|
|
51
|
+
if (q >= -27) {
|
|
52
|
+
c = (1n << (z + 127n)) / p + 1n
|
|
53
|
+
} else {
|
|
54
|
+
c = (1n << (2n * z + 128n)) / p + 1n
|
|
55
|
+
while (c >= LIMIT) {
|
|
56
|
+
c /= 2n
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
entries.push(c)
|
|
60
|
+
}
|
|
61
|
+
for (let q = 0; q <= LARGEST; q++) {
|
|
62
|
+
let p = 5n ** BigInt(q)
|
|
63
|
+
while (p < TOP) {
|
|
64
|
+
p *= 2n
|
|
65
|
+
}
|
|
66
|
+
while (p >= LIMIT) {
|
|
67
|
+
p /= 2n
|
|
68
|
+
}
|
|
69
|
+
entries.push(p)
|
|
70
|
+
}
|
|
71
|
+
for (const [i, c] of entries.entries()) {
|
|
72
|
+
if (c < TOP || c >= LIMIT) {
|
|
73
|
+
throw new Error(`gen-json-pow5: the entry for q = ${i + SMALLEST} does not have its top bit at bit 127`)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const words = entries.flatMap((c) => [c >> 64n, c & WORD])
|
|
78
|
+
const half = (w) => `0x${w.toString(16).padStart(8, "0")}`
|
|
79
|
+
const cases = words.flatMap((w, i) => [
|
|
80
|
+
` case ${i}:`,
|
|
81
|
+
` return jsonTokW64(${half(w >> 32n)}, ${half(w & 0xffffffffn)})`,
|
|
82
|
+
])
|
|
83
|
+
|
|
84
|
+
const BEGIN = "// gen-json-pow5:begin"
|
|
85
|
+
const END = "// gen-json-pow5:end"
|
|
86
|
+
const region = [
|
|
87
|
+
`${BEGIN} -- generated by scripts/gen-json-pow5.mjs; edit that, not this.`,
|
|
88
|
+
"/**",
|
|
89
|
+
` * The 128-bit truncation of 5^q, high word at \`2 × (q + ${-SMALLEST})\` and low word`,
|
|
90
|
+
` * after it, for q from ${SMALLEST} to ${LARGEST}: for q ≥ 0, 5^q shifted until its top bit`,
|
|
91
|
+
" * is bit 127; for q < 0, 2^b / 5^-q rounded up, for the b that puts its top",
|
|
92
|
+
" * bit there. Upstream's `power_of_five_128`.",
|
|
93
|
+
" *",
|
|
94
|
+
" * A function over a `switch` rather than an array for `std/crypto/sha512.ts`'s",
|
|
95
|
+
" * reason: a module constant cannot be an array, and LLVM turns a `switch`",
|
|
96
|
+
" * whose every arm is a constant into one read-only table. `index` is computed",
|
|
97
|
+
" * from the exponent, which `numberF64` has bounded.",
|
|
98
|
+
" */",
|
|
99
|
+
"const jsonTokPowerOfFive = (index: i32): u64 => {",
|
|
100
|
+
" switch (index) {",
|
|
101
|
+
...cases,
|
|
102
|
+
` // Unreachable: \`jsonTokEiselLemire\` asks only for 0 to ${words.length - 1}.`,
|
|
103
|
+
" default:",
|
|
104
|
+
" return toU64(0)",
|
|
105
|
+
" }",
|
|
106
|
+
"}",
|
|
107
|
+
END,
|
|
108
|
+
].join("\n")
|
|
109
|
+
|
|
110
|
+
const source = fs.readFileSync(target, "utf8")
|
|
111
|
+
const from = source.indexOf(BEGIN)
|
|
112
|
+
const to = source.indexOf(END)
|
|
113
|
+
if (from < 0 || to < from) {
|
|
114
|
+
console.error(`gen-json-pow5: no ${BEGIN} ... ${END} region in ${path.relative(root, target)}`)
|
|
115
|
+
process.exit(1)
|
|
116
|
+
}
|
|
117
|
+
const next = source.slice(0, from) + region + source.slice(to + END.length)
|
|
118
|
+
|
|
119
|
+
if (process.argv.includes("--check")) {
|
|
120
|
+
if (next !== source) {
|
|
121
|
+
console.error(
|
|
122
|
+
`gen-json-pow5: the table in ${path.relative(root, target)} is not what the generator writes; run node scripts/gen-json-pow5.mjs`
|
|
123
|
+
)
|
|
124
|
+
process.exit(1)
|
|
125
|
+
}
|
|
126
|
+
console.log(`gen-json-pow5: ${words.length} words, as generated`)
|
|
127
|
+
} else {
|
|
128
|
+
fs.writeFileSync(target, next)
|
|
129
|
+
console.log(`gen-json-pow5: wrote ${words.length} words to ${path.relative(root, target)}`)
|
|
130
|
+
}
|
|
@@ -80,7 +80,9 @@ const manifest = {
|
|
|
80
80
|
// MAIN package, which has carried `std` in its own `files` all along --
|
|
81
81
|
// so the fallback to `dist/` worked and the path a user actually gets did
|
|
82
82
|
// not. See docs/wp12-release.md and wp19 §5a.
|
|
83
|
-
|
|
83
|
+
// `docs` carries `AI.md`, which `nish --help` names to a coding agent by its
|
|
84
|
+
// absolute path, found under this package rather than the main one.
|
|
85
|
+
files: ["bin", "runtime", "scripts", "std", "docs", "LICENSE", "INSTALL.md"],
|
|
84
86
|
repository: main.repository,
|
|
85
87
|
bugs: main.bugs,
|
|
86
88
|
homepage: main.homepage,
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Every file of the attacker-facing surface is named in a security record's
|
|
3
|
+
// scope, or listed in the index's "Not yet audited" table with a reason.
|
|
4
|
+
//
|
|
5
|
+
// node scripts/security-scope.mjs check the tree (CI + npm test)
|
|
6
|
+
// node scripts/security-scope.mjs --root D check the tree under D instead
|
|
7
|
+
//
|
|
8
|
+
// The surface is `std/net/**/*.ts`, `std/crypto/*.ts` and `runtime/*.c`. A file
|
|
9
|
+
// is in scope when its repository path, or a glob that matches it, is
|
|
10
|
+
// backticked in the first cell of a row of a record's `## Scope` table, or in
|
|
11
|
+
// the Scope column of `docs/security/README.md`'s Areas table. A row of the
|
|
12
|
+
// "Not yet audited" table is refused when its file is covered or gone, so the
|
|
13
|
+
// list only shrinks. The rule it checks is CLAUDE.md's: new attacker-facing
|
|
14
|
+
// code ships with its record.
|
|
15
|
+
import fs from "node:fs"
|
|
16
|
+
import path from "node:path"
|
|
17
|
+
|
|
18
|
+
const args = process.argv.slice(2)
|
|
19
|
+
const at = args.indexOf("--root")
|
|
20
|
+
const root = at >= 0 ? path.resolve(args[at + 1]) : path.resolve(import.meta.dirname, "..")
|
|
21
|
+
const securityDir = path.join(root, "docs", "security")
|
|
22
|
+
|
|
23
|
+
const walk = (dir, keep) => {
|
|
24
|
+
if (!fs.existsSync(path.join(root, dir))) {
|
|
25
|
+
return []
|
|
26
|
+
}
|
|
27
|
+
const out = []
|
|
28
|
+
for (const entry of fs.readdirSync(path.join(root, dir), { withFileTypes: true })) {
|
|
29
|
+
const rel = `${dir}/${entry.name}`
|
|
30
|
+
if (entry.isDirectory()) {
|
|
31
|
+
out.push(...walk(rel, keep))
|
|
32
|
+
} else if (keep(entry.name)) {
|
|
33
|
+
out.push(rel)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const surface = [
|
|
40
|
+
...walk("std/net", (n) => n.endsWith(".ts")),
|
|
41
|
+
...fs
|
|
42
|
+
.readdirSync(path.join(root, "std", "crypto"))
|
|
43
|
+
.filter((n) => n.endsWith(".ts"))
|
|
44
|
+
.map((n) => `std/crypto/${n}`),
|
|
45
|
+
...fs
|
|
46
|
+
.readdirSync(path.join(root, "runtime"))
|
|
47
|
+
.filter((n) => n.endsWith(".c"))
|
|
48
|
+
.map((n) => `runtime/${n}`),
|
|
49
|
+
].sort()
|
|
50
|
+
|
|
51
|
+
const ticked = (text) => [...text.matchAll(/`([^`]+)`/g)].map((m) => m[1].trim())
|
|
52
|
+
const cells = (line) => line.split("|").slice(1, -1)
|
|
53
|
+
|
|
54
|
+
// A glob here is a path with `*` in its last part, nothing more.
|
|
55
|
+
const matches = (pattern, file) => {
|
|
56
|
+
if (!pattern.includes("*")) {
|
|
57
|
+
return pattern === file
|
|
58
|
+
}
|
|
59
|
+
const re = new RegExp(`^${pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*")}$`)
|
|
60
|
+
return re.test(file)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const patterns = new Set()
|
|
64
|
+
const index = fs.readFileSync(path.join(securityDir, "README.md"), "utf8").split("\n")
|
|
65
|
+
for (const name of fs.readdirSync(securityDir)) {
|
|
66
|
+
if (!name.endsWith(".md") || name === "README.md") {
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
const lines = fs.readFileSync(path.join(securityDir, name), "utf8").split("\n")
|
|
70
|
+
let inScope = false
|
|
71
|
+
for (const line of lines) {
|
|
72
|
+
if (line.startsWith("## ")) {
|
|
73
|
+
inScope = line.trim() === "## Scope"
|
|
74
|
+
} else if (inScope && line.startsWith("|")) {
|
|
75
|
+
for (const t of ticked(cells(line)[0] ?? "")) {
|
|
76
|
+
patterns.add(t)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The Areas table: its Scope column is the third. The "Not yet audited" table:
|
|
83
|
+
// file, then reason.
|
|
84
|
+
const pending = new Map()
|
|
85
|
+
let table = ""
|
|
86
|
+
for (const line of index) {
|
|
87
|
+
if (line.startsWith("## ")) {
|
|
88
|
+
table = line.slice(3).trim()
|
|
89
|
+
}
|
|
90
|
+
if (
|
|
91
|
+
!line.startsWith("|") ||
|
|
92
|
+
line.startsWith("| ---") ||
|
|
93
|
+
line.startsWith("| Area") ||
|
|
94
|
+
line.startsWith("| File")
|
|
95
|
+
) {
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
const row = cells(line)
|
|
99
|
+
if (table === "Areas") {
|
|
100
|
+
for (const t of ticked(row[2] ?? "")) {
|
|
101
|
+
patterns.add(t)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (table === "Not yet audited") {
|
|
105
|
+
const [file] = ticked(row[0] ?? "")
|
|
106
|
+
if (file) {
|
|
107
|
+
pending.set(file, (row[1] ?? "").trim())
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const problems = []
|
|
113
|
+
const covered = (file) => [...patterns].some((p) => matches(p, file))
|
|
114
|
+
for (const file of surface) {
|
|
115
|
+
if (covered(file)) {
|
|
116
|
+
if (pending.has(file)) {
|
|
117
|
+
problems.push(`${file}: in a record's scope, so its "Not yet audited" row goes`)
|
|
118
|
+
}
|
|
119
|
+
} else if (!pending.has(file)) {
|
|
120
|
+
problems.push(`${file}: in no record's scope; it ships with its docs/security/ record (CLAUDE.md)`)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const [file, reason] of pending) {
|
|
124
|
+
if (!surface.includes(file)) {
|
|
125
|
+
problems.push(`${file}: listed under "Not yet audited" but not on the surface`)
|
|
126
|
+
} else if (reason === "") {
|
|
127
|
+
problems.push(`${file}: its "Not yet audited" row gives no reason`)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (problems.length > 0) {
|
|
132
|
+
for (const p of problems) {
|
|
133
|
+
console.error(`security-scope: ${p}`)
|
|
134
|
+
}
|
|
135
|
+
process.exit(1)
|
|
136
|
+
}
|
|
137
|
+
console.log(
|
|
138
|
+
`security-scope: ${surface.length} files, ${surface.length - pending.size} in a record, ${pending.size} not yet audited`
|
|
139
|
+
)
|
package/scripts/smoke.sh
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
# A program is any examples/**/*.ts that declares `export const main`. It
|
|
14
14
|
# is expected to exit 0 unless it carries a `// smoke: exit <n>` comment; a
|
|
15
15
|
# `// smoke: argv <args>` comment passes those arguments on its command line
|
|
16
|
-
# (process.argv).
|
|
16
|
+
# (process.argv). Every program reads /dev/null for stdin, so a run is the
|
|
17
|
+
# same from a terminal as in CI. The script exits non-zero if any program fails to compile,
|
|
17
18
|
# link, or run with the expected status. Binaries and IR go to build/smoke/.
|
|
18
19
|
# Needs clang on PATH.
|
|
19
20
|
set -uo pipefail
|
|
@@ -73,7 +74,7 @@ for src in "${programs[@]}"; do
|
|
|
73
74
|
# `// smoke: argv <args>` is the program's command line (WP7 process.argv).
|
|
74
75
|
argv=$(sed -n 's#^// smoke: argv \(.*\)#\1#p' "$src" | head -n 1)
|
|
75
76
|
# shellcheck disable=SC2086
|
|
76
|
-
"$exe" $argv >"$out/$name.out" 2>"$out/$name.err"
|
|
77
|
+
"$exe" $argv </dev/null >"$out/$name.out" 2>"$out/$name.err"
|
|
77
78
|
got=$?
|
|
78
79
|
if [ "$got" -eq "$want" ]; then
|
|
79
80
|
status="ok (exit $got)"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Boost Software License - Version 1.0 - August 17th, 2003
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person or organization
|
|
4
|
+
obtaining a copy of the software and accompanying documentation covered by
|
|
5
|
+
this license (the "Software") to use, reproduce, display, distribute,
|
|
6
|
+
execute, and transmit the Software, and to prepare derivative works of the
|
|
7
|
+
Software, and to permit third-parties to whom the Software is furnished to
|
|
8
|
+
do so, all subject to the following:
|
|
9
|
+
|
|
10
|
+
The copyright notices in the Software and this entire statement, including
|
|
11
|
+
the above license grant, this restriction and the following disclaimer,
|
|
12
|
+
must be included in all copies of the Software, in whole or in part, and
|
|
13
|
+
all derivative works of the Software, unless such copies or derivative
|
|
14
|
+
works are solely in the form of machine-executable object code generated by
|
|
15
|
+
a source language processor.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
20
|
+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
21
|
+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
22
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
23
|
+
DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
====================================================
|
|
2
|
+
Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
3
|
+
|
|
4
|
+
Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
5
|
+
Permission to use, copy, modify, and distribute this
|
|
6
|
+
software is freely granted, provided that this notice
|
|
7
|
+
is preserved.
|
|
8
|
+
====================================================
|