@ai-ecoverse/slicc-kernel 1.196.51 → 1.196.53

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.
@@ -4300,7 +4300,7 @@ var OpfsFs = class {
4300
4300
  if (!missing2(err)) throw err;
4301
4301
  });
4302
4302
  }
4303
- async commitPrivateCopy(from, to, root, intent, copies, emptyBackup) {
4303
+ async commitPrivateCopy(from, to, root, intent, copies, emptyBackup, lock) {
4304
4304
  const { ino, ...owner } = root;
4305
4305
  const entries = await this.meta.get([from, to]);
4306
4306
  let mark = entries[0];
@@ -4313,7 +4313,7 @@ var OpfsFs = class {
4313
4313
  mark
4314
4314
  );
4315
4315
  }
4316
- if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino);
4316
+ if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino, lock);
4317
4317
  this.movePending(from, to);
4318
4318
  await this.restamp(to, copies);
4319
4319
  this.changed(from, to);
@@ -4405,13 +4405,18 @@ var OpfsFs = class {
4405
4405
  if (signal) await this.locks.request(key, { signal }, remove);
4406
4406
  else await this.locks.request(key, remove);
4407
4407
  }
4408
- async duplicate(handle, parent, name2, copies, rest2) {
4409
- if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
4410
- await copies.manifest?.record(await copiedEntry(handle, rest2));
4408
+ async duplicate(handle, parent, name2, copies, rest2, vacantOnly = false) {
4409
+ if (handle.kind === "file")
4410
+ return this.copyBytes(handle, parent, name2, { copies, vacantOnly }, rest2);
4411
+ if (vacantOnly && await this.handleExists(parent, name2)) throw fsError("EEXIST", name2);
4411
4412
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
4412
4413
  this.others++;
4414
+ await this.duplicateContents(handle, dir, copies, rest2, vacantOnly);
4415
+ }
4416
+ async duplicateContents(handle, dir, copies, rest2, vacantOnly = false) {
4417
+ await copies.manifest?.record(await copiedEntry(handle, rest2));
4413
4418
  for await (const child2 of handle.values())
4414
- await this.duplicate(child2, dir, child2.name, copies, rest2 + "/" + child2.name);
4419
+ await this.duplicate(child2, dir, child2.name, copies, rest2 + "/" + child2.name, vacantOnly);
4415
4420
  }
4416
4421
  hiddenBackups = /* @__PURE__ */ new Set();
4417
4422
  pendingSources = /* @__PURE__ */ new Map();
@@ -4553,6 +4558,49 @@ var OpfsFs = class {
4553
4558
  }
4554
4559
  await this.dropSwapIntent(intent, backup);
4555
4560
  }
4561
+ async vacantLegacyGeneration(from, to, generation) {
4562
+ const [mark, ...parents] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [
4563
+ from,
4564
+ ...prefixes(parentOf4(to))
4565
+ ]);
4566
+ return mark?.vacated === true && mark.ino === generation && !mark.copyCommit && !parents.some((p) => p?.vacated || p?.link !== void 0) && (await this.meta.under(to)).length === 0;
4567
+ }
4568
+ async resumeVacantLegacy(intent, rename, generation) {
4569
+ const { from, to, root } = rename;
4570
+ const stage = /^\..+\.[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
4571
+ if (!root || rename.replace || stage.test(baseOf(from)) || stage.test(baseOf(to))) return false;
4572
+ const source = await this.swapEntry(from), parent = await this.swapEntry(parentOf4(to));
4573
+ if (source?.kind !== "directory" || parent?.kind !== "directory") return false;
4574
+ const name2 = baseOf(to);
4575
+ const target = await this.locked(to, async () => {
4576
+ if (!await this.vacantLegacyGeneration(from, to, generation) || await this.handleExists(parent, name2))
4577
+ return void 0;
4578
+ return parent.getDirectoryHandle(name2, { create: true });
4579
+ });
4580
+ if (!target) return false;
4581
+ for await (const _ of target.keys()) return false;
4582
+ const copies = new Copies(this.meta, intent);
4583
+ await this.meta.remove([manifestRoot(intent)]);
4584
+ try {
4585
+ await this.duplicateContents(source, target, copies, "", true);
4586
+ } catch (err) {
4587
+ if (err.code === "EEXIST") return false;
4588
+ throw err;
4589
+ }
4590
+ await copies.manifest?.flush();
4591
+ if (!await this.vacantLegacyGeneration(from, to, generation) || (await this.root.resolve(source))?.join("/") !== from.slice(1) || (await this.root.resolve(target))?.join("/") !== to.slice(1))
4592
+ return false;
4593
+ await this.commitPrivateCopy(
4594
+ from,
4595
+ to,
4596
+ { ...root, ino: generation },
4597
+ intent,
4598
+ copies,
4599
+ void 0,
4600
+ rename.lock
4601
+ );
4602
+ return true;
4603
+ }
4556
4604
  async resumeCopiedTree(intent, rename) {
4557
4605
  const { from, to, root } = rename;
4558
4606
  const [mark, placed] = await this.meta.get([from, to]);
@@ -4561,16 +4609,16 @@ var OpfsFs = class {
4561
4609
  return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock);
4562
4610
  }
4563
4611
  if (mark?.vacated && mark.ino !== void 0 && mark.ino !== root?.ino) {
4564
- if (!mark.copyCommit)
4565
- return this.releaseSource(
4566
- intent,
4567
- from,
4568
- to,
4569
- mark.ino,
4570
- rename.lock,
4571
- !root || placed?.ino !== root.ino
4572
- );
4573
- return this.retireIntent(intent);
4612
+ if (mark.copyCommit) return this.retireIntent(intent);
4613
+ if (!placed && await this.resumeVacantLegacy(intent, rename, mark.ino)) return;
4614
+ return this.releaseSource(
4615
+ intent,
4616
+ from,
4617
+ to,
4618
+ mark.ino,
4619
+ rename.lock,
4620
+ !root || placed?.ino !== root.ino
4621
+ );
4574
4622
  }
4575
4623
  const left = await this.real(from);
4576
4624
  await this.meta.remove([manifestRoot(intent)]);
@@ -4837,6 +4885,7 @@ var OpfsFs = class {
4837
4885
  async copyBytes(handle, dir, name2, options, rest2) {
4838
4886
  const file = await this.io(handle.getFile());
4839
4887
  await options.copies?.manifest?.record(await copiedEntry(handle, rest2, file));
4888
+ if (options.vacantOnly && await this.handleExists(dir, name2)) throw fsError("EEXIST", name2);
4840
4889
  const made2 = await this.io(dir.getFileHandle(name2, { create: true }));
4841
4890
  const writable3 = await this.io(made2.createWritable());
4842
4891
  try {
@@ -10463,7 +10512,7 @@ function satisfies(version, range2) {
10463
10512
  }
10464
10513
 
10465
10514
  // src/version.ts
10466
- var KERNEL_VERSION = true ? "1.196.51" : "0.0.0-dev";
10515
+ var KERNEL_VERSION = true ? "1.196.53" : "0.0.0-dev";
10467
10516
  var OS_RELEASE = "6.0.0-slicc";
10468
10517
  function procVersion() {
10469
10518
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -23511,6 +23560,21 @@ var SealedBroker = class {
23511
23560
  }
23512
23561
  };
23513
23562
 
23563
+ // src/sudo-argv.ts
23564
+ var SUDO_VECTOR_MAX = 4096;
23565
+ var SUDO_INPUT_BYTES = 1024 * 1024;
23566
+ function budgetAfterArgs(args) {
23567
+ if (!Array.isArray(args)) return void 0;
23568
+ let remaining = args.length > SUDO_VECTOR_MAX ? -1 : SUDO_INPUT_BYTES;
23569
+ for (const word of args) {
23570
+ if (typeof word !== "string") return void 0;
23571
+ if (word.includes("\0")) return "nul";
23572
+ if (remaining >= 0)
23573
+ remaining = word.length + 1 > remaining ? -1 : remaining - storedSize(word) - 1;
23574
+ }
23575
+ return remaining;
23576
+ }
23577
+
23514
23578
  // src/sudo-files.ts
23515
23579
  var HEADER_BYTES = 256;
23516
23580
  async function fingerprint(bytes) {
@@ -23746,6 +23810,8 @@ var PLAIN2 = /^[A-Za-z0-9_@%+=:,./-]+$/;
23746
23810
  var CONTROL2 = /[\p{Cc}\u2028\u2029]/u;
23747
23811
  var CONTROLS = /[\p{Cc}\u2028\u2029]/gu;
23748
23812
  var SHOWN_MAX = 60;
23813
+ var DISPLAY_BYTES = 4096;
23814
+ var encoder9 = new TextEncoder();
23749
23815
  var KERNEL_SYNTAX = "[NOPASSWD] <user|%group|ALL> [(<target>)] [Cwd <dir>] [Stdin none] [ChainSha256 <sha256>] [RouteSha256 <sha256>] [Sha256 none|<file>=<sha256>\u2026] Cmnd <command\u2026|*>";
23750
23816
  var SUDOERS_SYNTAX = "<user|%group|ALL> ALL=[(<target>[,<target>\u2026])] [NOPASSWD:] <command\u2026|ALL>";
23751
23817
  var EXPECTED = `expected '${KERNEL_SYNTAX}' or '${SUDOERS_SYNTAX}'`;
@@ -23796,6 +23862,36 @@ function shellQuote(word) {
23796
23862
  function quoteWord(word) {
23797
23863
  return shellQuote(hasControl(word) ? withoutControl(word) : word);
23798
23864
  }
23865
+ function clip(text, bytes, marker = "\u2026") {
23866
+ const { read } = encoder9.encodeInto(text, new Uint8Array(bytes - encoder9.encode(marker).length));
23867
+ return text.slice(0, read) + marker;
23868
+ }
23869
+ function limitText(text, bytes) {
23870
+ return encoder9.encode(text.slice(0, bytes + 1)).length > bytes ? clip(text, bytes) : text;
23871
+ }
23872
+ function auditField(value2, bytes = 256) {
23873
+ return limitText(quoteWord(value2.slice(0, bytes + 1)), bytes);
23874
+ }
23875
+ async function commandDisplay(prefix, argv, suffix = "", fullArgv = argv) {
23876
+ const before = limitText(prefix, 2048);
23877
+ const after = limitText(suffix, 512);
23878
+ const limit = DISPLAY_BYTES - encoder9.encode(before + after).length;
23879
+ let room = limit;
23880
+ let text = "";
23881
+ for (const [i, arg] of argv.entries()) {
23882
+ const part = (i ? " " : "") + quoteWord(arg.slice(0, room + 1));
23883
+ room -= encoder9.encode(part).length;
23884
+ if (room < 0) {
23885
+ const marker = `\u2026 [sha256=${await argvDigest(fullArgv)}]`;
23886
+ return before + clip(text + part, limit, marker) + after;
23887
+ }
23888
+ text += part;
23889
+ }
23890
+ return before + text + after;
23891
+ }
23892
+ function wordDisplay(argv, suffix) {
23893
+ return commandDisplay("sudo: ", argv.slice(0, 1), suffix, argv);
23894
+ }
23799
23895
  function addPart(word, part) {
23800
23896
  const last = word.length - 1;
23801
23897
  if (part === null) {
@@ -24350,11 +24446,14 @@ function stdinMatches(rule, stdin) {
24350
24446
  function recordable(cwd, argv) {
24351
24447
  return !hasControl(cwd) && !argv.some(hasControl);
24352
24448
  }
24353
- function changedText(word) {
24354
- return `sudo: ${quoteWord(word)} changed since it was approved`;
24449
+ function changedText(argv) {
24450
+ return wordDisplay(argv, " changed since it was approved");
24451
+ }
24452
+ function requestedText(argv, hint = "") {
24453
+ return wordDisplay(argv, " changed since it was requested" + hint);
24355
24454
  }
24356
- function requestedText(word) {
24357
- return `sudo: ${quoteWord(word)} changed since it was requested`;
24455
+ function auditPrefix(user, tty, cwd, target, kind) {
24456
+ return `sudo: ${auditField(user)} : TTY=${auditField(tty)} ; PWD=${auditField(cwd, 768)} ; USER=${auditField(target)} ; ${kind} ; COMMAND=`;
24358
24457
  }
24359
24458
  function changedFile(approved, now) {
24360
24459
  const files = /* @__PURE__ */ new Set([...Object.keys(approved), ...Object.keys(now)]);
@@ -24392,16 +24491,15 @@ function stampOf(files) {
24392
24491
  }
24393
24492
  var REPLAY_ID = /^[!-~]{1,256}$/;
24394
24493
  var REPLAY_TAGS_MAX = 64;
24395
- var REPLAY_ARGV_MAX = 4096;
24396
24494
  var REPLAY_BYTES_MAX = 1024 * 1024;
24397
24495
  var NOT_A_REQUEST = "sudo: that isn't a sudo request this kernel can run";
24398
24496
  function strings2(value2, max) {
24399
24497
  return Array.isArray(value2) && value2.length <= max && value2.every((s) => typeof s === "string");
24400
24498
  }
24401
24499
  function words(value2) {
24402
- if (!strings2(value2, REPLAY_ARGV_MAX) || value2.length === 0) return false;
24403
- const bytes = value2.reduce((n, s) => n + s.length + 1, 0);
24404
- return bytes <= REPLAY_BYTES_MAX && !value2.some((s) => s.includes("\0"));
24500
+ if (!Array.isArray(value2) || value2.length === 0 || value2.length > SUDO_VECTOR_MAX) return false;
24501
+ const remaining = budgetAfterArgs(value2);
24502
+ return typeof remaining === "number" && remaining >= 0;
24405
24503
  }
24406
24504
  var FACT_OVERHEAD = 66;
24407
24505
  function factsFit(files) {
@@ -24896,8 +24994,9 @@ var Sudo = class {
24896
24994
  const st = await fs.stat(path);
24897
24995
  return st.isFile && (st.mode & 73) !== 0 ? path : void 0;
24898
24996
  }
24899
- async locate(word, cwd, reads, target) {
24997
+ async locate(argv, cwd, reads, target) {
24900
24998
  const fs = this.o.planFs?.(reads) ?? this.o.fs;
24999
+ const [word = ""] = argv;
24901
25000
  const candidates = word.includes("/") ? [askedPath(cwd, word)] : SECURE_PATH.split(":").map((dir) => `${dir}/${word}`);
24902
25001
  const cred = credOf(target);
24903
25002
  let denial;
@@ -24907,9 +25006,10 @@ var Sudo = class {
24907
25006
  if (path !== void 0) return { path, asked };
24908
25007
  } catch (err) {
24909
25008
  const code = err.code;
24910
- if (code === "EACCES") denial = failed2(code, `sudo: ${word}: Permission denied`);
25009
+ if (code === "EACCES")
25010
+ denial = failed2(code, await wordDisplay(argv, ": Permission denied"));
24911
25011
  else if (code === "ELOOP")
24912
- return failed2(code, `sudo: ${word}: Too many levels of symbolic links`);
25012
+ return failed2(code, await wordDisplay(argv, ": Too many levels of symbolic links"));
24913
25013
  }
24914
25014
  }
24915
25015
  return denial;
@@ -24980,12 +25080,16 @@ ${SCRIPT_HELP}
24980
25080
  const target = await this.lookup(r.target);
24981
25081
  if (!target) return failed2("ENOENT", `sudo: unknown user ${r.target}`);
24982
25082
  const cred = credOf(self);
24983
- const [word = "", ...args] = r.argv;
25083
+ const args = r.argv.slice(1);
24984
25084
  const argv = [r.path, ...args];
24985
25085
  const rules = await this.replayRules(self, target, r, argv);
24986
- const denied2 = () => failed2(
25086
+ const denied2 = async () => failed2(
24987
25087
  "EACCES",
24988
- `sudo: ${self.name} may no longer ask to run ${r.argv.map(quoteWord).join(" ")} as ${target.name}`
25088
+ await commandDisplay(
25089
+ `sudo: ${self.name} may no longer ask to run `,
25090
+ r.argv,
25091
+ ` as ${target.name}`
25092
+ )
24989
25093
  );
24990
25094
  if (rules?.length === 0) return denied2();
24991
25095
  if (await this.canonical(r.cwd) !== r.cwd) {
@@ -24998,23 +25102,23 @@ ${SCRIPT_HELP}
24998
25102
  );
24999
25103
  }
25000
25104
  const reads = this.reads();
25001
- const located = await this.locate(word, r.cwd, reads, target);
25105
+ const located = await this.locate(r.argv, r.cwd, reads, target);
25002
25106
  if (located && "error" in located) return located;
25003
25107
  if (!located) {
25004
25108
  const gone = await this.missingBacking(r.bound, r.path);
25005
- return gone ? failed2("EPERM", requestedText(word)) : failed2("ENOENT", `sudo: ${word}: command not found`);
25109
+ return gone ? failed2("EPERM", await requestedText(r.argv)) : failed2("ENOENT", await wordDisplay(r.argv, ": command not found"));
25006
25110
  }
25007
25111
  const { path, asked } = located;
25008
- if (path !== r.path) return failed2("EPERM", requestedText(word));
25112
+ if (path !== r.path) return failed2("EPERM", await requestedText(r.argv));
25009
25113
  const bound3 = await this.bound(path, r.cwd, asked, void 0, reads);
25010
- if (!bound3) return failed2("EPERM", requestedText(word));
25114
+ if (!bound3) return failed2("EPERM", await requestedText(r.argv));
25011
25115
  const changed2 = changedDecision(r.bound, r, bound3, path);
25012
25116
  if (changed2 !== void 0) {
25013
25117
  const missing7 = ["chainSha256", "routeSha256"].filter(
25014
25118
  (key) => bound3[key] !== void 0 && r[key] === void 0
25015
25119
  );
25016
25120
  const hint = missing7.length && changedFile(r.bound, bound3.hashes) === void 0 ? `; the saved request lacks ${missing7.join(" and ")}; pass back the whole request from approve unchanged` : "";
25017
- return failed2("EPERM", requestedText(word) + hint);
25121
+ return failed2("EPERM", await requestedText(r.argv, hint));
25018
25122
  }
25019
25123
  if (bound3.writableEnvPath && rules && !rules.some((rule) => pinned(rule, bound3.hashes, bound3)))
25020
25124
  return denied2();
@@ -25034,7 +25138,10 @@ ${SCRIPT_HELP}
25034
25138
  asked
25035
25139
  );
25036
25140
  (this.o.warn ?? console.warn)(
25037
- `sudo: ${self.name} : TTY=unknown ; PWD=${quoteWord(r.cwd)} ; USER=${target.name} ; REPLAY=${r.id} ; COMMAND=${argv.map(quoteWord).join(" ")}`
25141
+ await commandDisplay(
25142
+ auditPrefix(self.name, "unknown", r.cwd, target.name, `REPLAY=${auditField(r.id)}`),
25143
+ argv
25144
+ )
25038
25145
  );
25039
25146
  return { grant, caller: self, target, tags: r.tags };
25040
25147
  }
@@ -25050,10 +25157,14 @@ ${SCRIPT_HELP}
25050
25157
  async command(s, root, mine, call) {
25051
25158
  const { caller, self, target, parsed: parsed3 } = s;
25052
25159
  const { cred } = caller;
25053
- const [word = "", ...args] = parsed3.command;
25054
- const notAllowed = () => failed2(
25160
+ const args = parsed3.command.slice(1);
25161
+ const notAllowed = async () => failed2(
25055
25162
  "EPERM",
25056
- `sudo: ${self.name} is not allowed to run ${parsed3.command.map(quoteWord).join(" ")} as ${target.name}`
25163
+ await commandDisplay(
25164
+ `sudo: ${self.name} is not allowed to run `,
25165
+ parsed3.command,
25166
+ ` as ${target.name}`
25167
+ )
25057
25168
  );
25058
25169
  if (!root && mine.length === 0) return notAllowed();
25059
25170
  const cwd = await this.canonical(call.cwd, cred);
@@ -25064,10 +25175,11 @@ ${SCRIPT_HELP}
25064
25175
  );
25065
25176
  }
25066
25177
  const reads = this.reads();
25067
- const located = await this.locate(word, cwd, reads, target);
25178
+ const located = await this.locate(parsed3.command, cwd, reads, target);
25068
25179
  if (located && "error" in located) return located;
25069
25180
  const bound3 = located && await this.bound(located.path, cwd, located.asked, caller.pid, reads);
25070
- if (!located || !bound3) return failed2("ENOENT", `sudo: ${word}: command not found`);
25181
+ if (!located || !bound3)
25182
+ return failed2("ENOENT", await wordDisplay(parsed3.command, ": command not found"));
25071
25183
  const { path, asked } = located;
25072
25184
  const argv = [path, ...args];
25073
25185
  const applicable = mine.filter(
@@ -25079,7 +25191,7 @@ ${SCRIPT_HELP}
25079
25191
  if (matching.length === 0) return notAllowed();
25080
25192
  if (!parsed3.reset && this.timestamps.current(s.owner, s.policy, stampOf(bound3))) {
25081
25193
  this.timestamps.stamp(s.owner, s.policy, stampOf(bound3));
25082
- this.logged(s, cwd, argv);
25194
+ await this.logged(s, cwd, argv);
25083
25195
  return grant();
25084
25196
  }
25085
25197
  if (parsed3.nonInteractive) return failed2("EPERM", "sudo: a password is required");
@@ -25100,11 +25212,11 @@ ${SCRIPT_HELP}
25100
25212
  if (await this.canonical(call.cwd, cred) !== cwd || !await this.reachable(cred, cwd)) {
25101
25213
  return failed2("EACCES", `sudo: ${call.cwd} changed while the request waited`);
25102
25214
  }
25103
- if (await this.moved(bound3)) return failed2("EPERM", changedText(word));
25215
+ if (await this.moved(bound3)) return failed2("EPERM", await changedText(parsed3.command));
25104
25216
  if (answer2.answer === "once" && !answer2.person) return grant();
25105
25217
  const now = await this.bound(path, cwd, asked, caller.pid);
25106
25218
  if (!now || changedDecision(bound3.hashes, bound3, now, path) !== void 0)
25107
- return failed2("EPERM", changedText(word));
25219
+ return failed2("EPERM", await changedText(parsed3.command));
25108
25220
  const shown2 = recordable(cwd, [...parsed3.command, ...Object.keys(bound3.hashes)]);
25109
25221
  const result = answer2.answer === "once" ? grant() : await this.always(
25110
25222
  self,
@@ -25150,13 +25262,12 @@ ${SCRIPT_HELP}
25150
25262
  stamped(s, answer2, bound3 = {}) {
25151
25263
  if (answer2.person && !s.parsed.reset) this.timestamps.stamp(s.owner, s.policy, bound3);
25152
25264
  }
25153
- logged(s, cwd, argv) {
25265
+ async logged(s, cwd, argv) {
25154
25266
  const { caller, self, target, owner, policy } = s;
25155
25267
  const type = policy.type === "tty" && !owner.terminal ? "ppid" : policy.type;
25156
25268
  const tty = owner.terminal?.tty ?? caller.tty ?? "unknown";
25157
- const command = argv.map(quoteWord).join(" ");
25158
25269
  (this.o.warn ?? console.warn)(
25159
- `sudo: ${self.name} : TTY=${tty} ; PWD=${quoteWord(cwd)} ; USER=${target.name} ; TIMESTAMP=${type} ; COMMAND=${command}`
25270
+ await commandDisplay(auditPrefix(self.name, tty, cwd, target.name, `TIMESTAMP=${type}`), argv)
25160
25271
  );
25161
25272
  }
25162
25273
  async always(self, target, line, shown2, grant) {
@@ -29199,10 +29310,10 @@ var ANY_PLACEHOLDER = /fnox_proxy_[0-9a-f]{24}/g;
29199
29310
  var REQUEST_LINE2 = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+) ([\x21-\x7e]+) HTTP\/1\.[01]$/;
29200
29311
  var HEADER_LINE = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+):[ \t]*(.*?)[ \t]*$/;
29201
29312
  var BASIC2 = /^(Basic[ \t]+)([A-Za-z0-9+/]+={0,2})$/i;
29202
- var encoder9 = new TextEncoder();
29313
+ var encoder10 = new TextEncoder();
29203
29314
  function binary(text) {
29204
29315
  let out = "";
29205
- for (const b of encoder9.encode(text)) out += String.fromCharCode(b);
29316
+ for (const b of encoder10.encode(text)) out += String.fromCharCode(b);
29206
29317
  return out;
29207
29318
  }
29208
29319
  function sniffHttp1(start2) {
@@ -29246,7 +29357,7 @@ function replaced(text, values) {
29246
29357
  function usable2(values) {
29247
29358
  const out = {};
29248
29359
  for (const [ph, value2] of Object.entries(values ?? {}))
29249
- if (encoder9.encode(value2).length >= MIN_VALUE) out[ph] = value2;
29360
+ if (encoder10.encode(value2).length >= MIN_VALUE) out[ph] = value2;
29250
29361
  return out;
29251
29362
  }
29252
29363
  async function substituteHead(head, ask) {
@@ -29310,7 +29421,7 @@ function prepFails(prepared) {
29310
29421
  }
29311
29422
 
29312
29423
  // src/kernel/net/sealed-scram.ts
29313
- var encoder10 = new TextEncoder();
29424
+ var encoder11 = new TextEncoder();
29314
29425
  function base64Bytes(text) {
29315
29426
  try {
29316
29427
  return Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
@@ -29382,7 +29493,7 @@ async function hmac(key, data) {
29382
29493
  return new Uint8Array(await crypto.subtle.sign("HMAC", k, data));
29383
29494
  }
29384
29495
  async function scramKeys(password, x) {
29385
- const base = await crypto.subtle.importKey("raw", encoder10.encode(password), "PBKDF2", false, [
29496
+ const base = await crypto.subtle.importKey("raw", encoder11.encode(password), "PBKDF2", false, [
29386
29497
  "deriveBits"
29387
29498
  ]);
29388
29499
  const salted = new Uint8Array(
@@ -29397,14 +29508,14 @@ async function scramKeys(password, x) {
29397
29508
  256
29398
29509
  )
29399
29510
  );
29400
- const clientKey = await hmac(salted, encoder10.encode("Client Key"));
29511
+ const clientKey = await hmac(salted, encoder11.encode("Client Key"));
29401
29512
  const stored2 = new Uint8Array(
29402
29513
  await crypto.subtle.digest("SHA-256", clientKey)
29403
29514
  );
29404
- const auth = encoder10.encode(`${x.clientFirstBare},${x.serverFirst},${x.clientFinalBare}`);
29515
+ const auth = encoder11.encode(`${x.clientFirstBare},${x.serverFirst},${x.clientFinalBare}`);
29405
29516
  const signature = await hmac(stored2, auth);
29406
29517
  const proof = clientKey.map((b, i) => b ^ signature[i]);
29407
- const serverKey = await hmac(salted, encoder10.encode("Server Key"));
29518
+ const serverKey = await hmac(salted, encoder11.encode("Server Key"));
29408
29519
  const serverSignature = await hmac(serverKey, auth);
29409
29520
  for (const k of [salted, clientKey, stored2, signature, serverKey]) k.fill(0);
29410
29521
  return { proof, serverSignature };
@@ -32904,20 +33015,6 @@ var PATH_FLAGS = PATH_ONLY | 65536 | 131072;
32904
33015
  var KEYBOARD = /* @__PURE__ */ new Set([SIG.INT, SIG.QUIT, SIG.TSTP]);
32905
33016
  var STUCK_ESCAPES = /* @__PURE__ */ new Set([SIG.INT, SIG.TERM, SIG.QUIT, SIG.HUP]);
32906
33017
  var DEFAULT_UMASK2 = 18;
32907
- var SUDO_VECTOR_MAX = 4096;
32908
- var SUDO_INPUT_BYTES = 1024 * 1024;
32909
- function budgetAfterArgs(args) {
32910
- if (!Array.isArray(args)) throw new KernelError("EINVAL");
32911
- if (args.length > SUDO_VECTOR_MAX) return -1;
32912
- let remaining = SUDO_INPUT_BYTES;
32913
- for (const word of args) {
32914
- if (typeof word !== "string") throw new KernelError("EINVAL");
32915
- if (word.length + 1 > remaining) return -1;
32916
- remaining -= storedSize(word) + 1;
32917
- if (remaining < 0) return -1;
32918
- }
32919
- return remaining;
32920
- }
32921
33018
  function sudoVariables(value2, term, budget) {
32922
33019
  const input = typeof value2 === "object" && value2 !== null ? value2 : {};
32923
33020
  const env = /* @__PURE__ */ Object.create(null);
@@ -35006,6 +35103,9 @@ var WasmProcess = class _WasmProcess {
35006
35103
  const { sudo } = this.options;
35007
35104
  if (!sudo) throw new KernelError("ENOSYS");
35008
35105
  const budget = budgetAfterArgs(req.args);
35106
+ if (budget === "nul")
35107
+ return { errno: "EINVAL", error: "sudo: an argument contains a NUL character" };
35108
+ if (budget === void 0) throw new KernelError("EINVAL");
35009
35109
  if (budget < 0) return { errno: "E2BIG", error: "sudo: the submitted arguments are too large" };
35010
35110
  const term = typeof req.term === "string" ? req.term : void 0;
35011
35111
  const submitted = sudoVariables(req.env, term, budget);
@@ -35039,8 +35139,7 @@ var WasmProcess = class _WasmProcess {
35039
35139
  })
35040
35140
  };
35041
35141
  } catch (err) {
35042
- if (err instanceof ChangedError)
35043
- return { error: changedText(argv[0] ?? asked), errno: err.code };
35142
+ if (err instanceof ChangedError) return { error: await changedText(argv), errno: err.code };
35044
35143
  throw err;
35045
35144
  }
35046
35145
  }
@@ -39636,7 +39735,7 @@ var LAYOUT = [
39636
39735
  var IN_TREE = /* @__PURE__ */ new Set([SUDO_PATH, VISUDO_PATH, CRONTAB_PATH, SEALED_BIN]);
39637
39736
  var LOAD_SAMPLE_MS = 5e3;
39638
39737
  var LOAD_WINDOWS_MS = [6e4, 3e5, 9e5];
39639
- var encoder11 = new TextEncoder();
39738
+ var encoder12 = new TextEncoder();
39640
39739
  var USERS_MODES = ["off", "report", "enforce"];
39641
39740
  function usersMode(mode = "off") {
39642
39741
  if (USERS_MODES.includes(mode)) return mode;
@@ -43463,7 +43562,7 @@ var Launcher = class {
43463
43562
  account,
43464
43563
  options.session
43465
43564
  );
43466
- const report = (message3) => options.onData(encoder11.encode(`${message3}\r
43565
+ const report = (message3) => options.onData(encoder12.encode(`${message3}\r
43467
43566
  `));
43468
43567
  const handle = await this.launch(planned, {
43469
43568
  ...reserved2,
@@ -43511,7 +43610,7 @@ var Launcher = class {
43511
43610
  };
43512
43611
  const stdout = collect2(out, options.onStdout);
43513
43612
  const stderr = collect2(err, options.onStderr);
43514
- const report = (message3) => stderr(encoder11.encode(`${message3}
43613
+ const report = (message3) => stderr(encoder12.encode(`${message3}
43515
43614
  `));
43516
43615
  if (!planned) {
43517
43616
  const directory = !missingFile && await this.directory(file, this.fs.resolvePath(cwd, file));
@@ -43552,21 +43651,20 @@ var Launcher = class {
43552
43651
  this.resetCatalogs();
43553
43652
  const req = { file: grant.file, argv: grant.argv, env: grant.env, cwd: grant.cwd };
43554
43653
  const ctx = { ppid: 0, cred: grant.cred, scope: "", grant };
43555
- const word = grant.argv[0] ?? grant.asked;
43556
- const requested = (err2) => {
43557
- if (err2 instanceof ChangedError) throw sudoFailure(err2.code, requestedText(word));
43654
+ const requested = async (err2) => {
43655
+ if (err2 instanceof ChangedError) throw sudoFailure(err2.code, await requestedText(grant.argv));
43558
43656
  throw err2;
43559
43657
  };
43560
- const planned = await this.planOne(req, ctx).catch((err2) => {
43561
- if (err2 instanceof ChangedError) requested(err2);
43658
+ const planned = await this.planOne(req, ctx).catch(async (err2) => {
43659
+ if (err2 instanceof ChangedError) return requested(err2);
43562
43660
  const code = sudoCause(err2);
43563
- if (code === "ENOENT") throw sudoFailure(code, `sudo: ${quoteWord(word)}: command not found`);
43564
- throw sudoFailure(code, `sudo: ${quoteWord(word)}: ${ERRNO_TEXT[code] ?? code}`);
43661
+ const reason = code === "ENOENT" ? "command not found" : ERRNO_TEXT[code] ?? code;
43662
+ throw sudoFailure(code, await wordDisplay(grant.argv, ": " + reason));
43565
43663
  });
43566
43664
  const pin = await this.unchanged(planned, grant.file, grant.cwd, grant).catch(requested);
43567
43665
  const fds = await this.sudoOutputs(options, caller, this.stackFor(tags, tagged.tagBase));
43568
43666
  const err = fds.get(2).file;
43569
- const report = (message3) => void Promise.resolve(err.write?.(encoder11.encode(`${message3}
43667
+ const report = (message3) => void Promise.resolve(err.write?.(encoder12.encode(`${message3}
43570
43668
  `))).catch(() => void 0);
43571
43669
  const replan = () => this.planOne(req, ctx);
43572
43670
  const recheck = this.approvedChain(planned, grant.file, grant.cwd, grant);