@ai-ecoverse/slicc-kernel 1.196.36 → 1.196.38

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.
@@ -10254,7 +10254,7 @@ function satisfies(version, range2) {
10254
10254
  }
10255
10255
 
10256
10256
  // src/version.ts
10257
- var KERNEL_VERSION = true ? "1.196.36" : "0.0.0-dev";
10257
+ var KERNEL_VERSION = true ? "1.196.38" : "0.0.0-dev";
10258
10258
  var OS_RELEASE = "6.0.0-slicc";
10259
10259
  function procVersion() {
10260
10260
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -10403,12 +10403,22 @@ async function withPackagePaths(fs, pkg, command, provenance) {
10403
10403
  if (!command.env) return command;
10404
10404
  const env = {};
10405
10405
  const envPaths = /* @__PURE__ */ new Set();
10406
+ const missingEnv = {};
10406
10407
  for (const [key, value2] of Object.entries(command.env)) {
10407
10408
  const path = !value2.startsWith("/") && value2.includes("/") && inside(pkg, value2);
10408
- if (path && provenance) envPaths.add(path);
10409
- env[key] = path && await fs.exists(path) ? path : value2;
10409
+ const present4 = path && await fs.exists(path);
10410
+ if (path && provenance) {
10411
+ envPaths.add(path);
10412
+ if (!present4) missingEnv[key] = { pkg, value: value2 };
10413
+ }
10414
+ env[key] = present4 ? path : value2;
10410
10415
  }
10411
- return { ...command, env, ...envPaths.size ? { envPaths: [...envPaths] } : {} };
10416
+ return {
10417
+ ...command,
10418
+ env,
10419
+ ...envPaths.size ? { envPaths: [...envPaths] } : {},
10420
+ ...Object.keys(missingEnv).length ? { missingEnv } : {}
10421
+ };
10412
10422
  }
10413
10423
  async function packages(fs, modules) {
10414
10424
  const names2 = await fs.readdir(modules).catch(() => []);
@@ -11189,27 +11199,27 @@ function hashId(text) {
11189
11199
  return hex4(a) + hex4(b);
11190
11200
  }
11191
11201
  function split2(text, count3) {
11192
- const words3 = [];
11202
+ const words2 = [];
11193
11203
  let rest2 = text;
11194
11204
  for (let i = 0; i < count3; i++) {
11195
11205
  const match = /^(\S+)\s+/.exec(rest2);
11196
11206
  if (!match) return void 0;
11197
- words3.push(match[1]);
11207
+ words2.push(match[1]);
11198
11208
  rest2 = rest2.slice(match[0].length);
11199
11209
  }
11200
- return [words3, rest2.trim()];
11210
+ return [words2, rest2.trim()];
11201
11211
  }
11202
11212
  function jobOf(content, pending, ctx, env) {
11203
11213
  const fields = content.startsWith("@") ? 1 : 5;
11204
11214
  const parts2 = split2(content, fields + (ctx.system ? 1 : 0));
11205
11215
  if (!parts2 || parts2[1] === "") throw new Error("no command");
11206
- const [words3, command] = parts2;
11207
- const schedule = words3.slice(0, fields).join(" ");
11216
+ const [words2, command] = parts2;
11217
+ const schedule = words2.slice(0, fields).join(" ");
11208
11218
  const when = parseWhen(schedule);
11209
11219
  const zone = env.CRON_TZ;
11210
11220
  if (zone && !when.reboot && canonicalZone(zone) === void 0)
11211
11221
  throw new Error(`CRON_TZ: unknown time zone "${zone}"`);
11212
- const user = ctx.system ? words3[fields] : void 0;
11222
+ const user = ctx.system ? words2[fields] : void 0;
11213
11223
  if (user !== void 0 && !USER_NAME.test(user)) throw new Error(`bad user name ${user}`);
11214
11224
  if (pending !== void 0 && !JOB_NAME.test(pending))
11215
11225
  throw new Error(`bad job name "${pending}"`);
@@ -23462,21 +23472,21 @@ function unescaped2(double) {
23462
23472
  }
23463
23473
  function splitWords(text) {
23464
23474
  const piece = /'([^']*)'|"((?:[^"\\]|\\[\s\S])*)"|\\([\s\S])|([^\s'"\\]+)|(\s+)/y;
23465
- const words3 = [];
23475
+ const words2 = [];
23466
23476
  let word;
23467
23477
  while (piece.lastIndex < text.length) {
23468
23478
  const m = piece.exec(text);
23469
23479
  if (!m) return void 0;
23470
23480
  const [, single, double, escaped, plain3, space] = m;
23471
23481
  if (space !== void 0) {
23472
- if (word !== void 0) words3.push(word);
23482
+ if (word !== void 0) words2.push(word);
23473
23483
  word = void 0;
23474
23484
  continue;
23475
23485
  }
23476
23486
  word = (word ?? "") + (single ?? (double !== void 0 ? unescaped2(double) : escaped ?? plain3));
23477
23487
  }
23478
- if (word !== void 0) words3.push(word);
23479
- return words3;
23488
+ if (word !== void 0) words2.push(word);
23489
+ return words2;
23480
23490
  }
23481
23491
  function shellQuote(word) {
23482
23492
  return PLAIN2.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
@@ -23499,14 +23509,14 @@ function addPlain(word, plain3) {
23499
23509
  }
23500
23510
  function splitPatterns(text) {
23501
23511
  const piece = /'([^']*)'|"((?:[^"\\]|\\[\s\S])*)"|\\([\s\S])|([^\s'"\\]+)|(\s+)/y;
23502
- const words3 = [];
23512
+ const words2 = [];
23503
23513
  let word;
23504
23514
  while (piece.lastIndex < text.length) {
23505
23515
  const m = piece.exec(text);
23506
23516
  if (!m) return void 0;
23507
23517
  const [, single, double, escaped, plain3, space] = m;
23508
23518
  if (space !== void 0) {
23509
- if (word !== void 0) words3.push(word);
23519
+ if (word !== void 0) words2.push(word);
23510
23520
  word = void 0;
23511
23521
  continue;
23512
23522
  }
@@ -23514,8 +23524,8 @@ function splitPatterns(text) {
23514
23524
  if (plain3 !== void 0) addPlain(word, plain3);
23515
23525
  else addPart(word, single ?? (double !== void 0 ? unescaped2(double) : escaped));
23516
23526
  }
23517
- if (word !== void 0) words3.push(word);
23518
- return words3;
23527
+ if (word !== void 0) words2.push(word);
23528
+ return words2;
23519
23529
  }
23520
23530
  var literal = (pattern) => pattern.map((p) => p ?? "*").join("");
23521
23531
  var isAny = (pattern) => pattern?.length === 1 && pattern[0] === null;
@@ -23591,14 +23601,14 @@ function whoError(who) {
23591
23601
  return `expected a user name, %group or ALL first, not ${shown(who)}`;
23592
23602
  }
23593
23603
  function cwdOf(word) {
23594
- const words3 = splitWords(word);
23595
- const path = words3?.length === 1 ? words3[0] : "";
23604
+ const words2 = splitWords(word);
23605
+ const path = words2?.length === 1 ? words2[0] : "";
23596
23606
  return path.startsWith("/") ? normalizePath(path) : "";
23597
23607
  }
23598
23608
  function commandOf2(text, after) {
23599
- const words3 = splitPatterns(text);
23600
- if (words3 === void 0) return "a quote in the command is not closed, or it ends in a \\";
23601
- const [first, ...args] = words3;
23609
+ const words2 = splitPatterns(text);
23610
+ if (words2 === void 0) return "a quote in the command is not closed, or it ends in a \\";
23611
+ const [first, ...args] = words2;
23602
23612
  const path = first ? literal(first) : "";
23603
23613
  if (path === "") return `expected a command after ${after}`;
23604
23614
  if (!path.startsWith("/")) return `expected an absolute command path, not ${shown(path)}`;
@@ -23781,14 +23791,14 @@ function legacyApproval(line, file, rule) {
23781
23791
  const stdin = rule.stdin === void 0 ? "" : "Stdin none ";
23782
23792
  const prefix = `NOPASSWD ${rule.who} (${rule.target}) ${cwd}${stdin}Cmnd `;
23783
23793
  if (!line.startsWith(prefix)) return rule;
23784
- const words3 = line.slice(prefix.length).trimEnd();
23794
+ const words2 = line.slice(prefix.length).trimEnd();
23785
23795
  if (cmnd.args === void 0) {
23786
- if (words3 !== quote(cmnd.path)) return rule;
23796
+ if (words2 !== quote(cmnd.path)) return rule;
23787
23797
  return { ...rule, cmnd: { ...cmnd, args: [] }, ...stdin ? {} : { sha256: {} } };
23788
23798
  }
23789
23799
  if (cmnd.args.some((arg) => arg.includes(null))) return rule;
23790
- const current = rule.cwd !== void 0 && words3 === formatCommand(cmnd, quote);
23791
- const earliest = !stdin && words3 === [cmnd.path, ...cmnd.args.map(literal)].map(quote).join(" ");
23800
+ const current = rule.cwd !== void 0 && words2 === formatCommand(cmnd, quote);
23801
+ const earliest = !stdin && words2 === [cmnd.path, ...cmnd.args.map(literal)].map(quote).join(" ");
23792
23802
  return current || earliest ? { ...rule, sha256: {} } : rule;
23793
23803
  }
23794
23804
  function kernelLine(m, line, file) {
@@ -24939,8 +24949,8 @@ ${lines3}
24939
24949
  const st = await fs.lstat(path).catch(() => void 0);
24940
24950
  if (st && !await this.trusted(path)) return false;
24941
24951
  const old = st ? await fs.readFile(path) : "";
24942
- const words3 = recordedCommand(argv);
24943
- const line = `NOPASSWD ${self.name} (${target.name}) Cwd ${quoteWord(cwd)} Stdin none ${sha256Text(bound3, routeSha256, chainSha256)}Cmnd ${words3}
24952
+ const words2 = recordedCommand(argv);
24953
+ const line = `NOPASSWD ${self.name} (${target.name}) Cwd ${quoteWord(cwd)} Stdin none ${sha256Text(bound3, routeSha256, chainSha256)}Cmnd ${words2}
24944
24954
  `;
24945
24955
  const text = old === "" || old.endsWith("\n") ? `${old}${line}` : `${old}
24946
24956
  ${line}`;
@@ -26247,8 +26257,8 @@ function ipv6(host) {
26247
26257
  const head = groups(halves[0]);
26248
26258
  const back = halves.length === 2 ? groups(halves[1]) : [];
26249
26259
  if (![...head, ...back].every((g) => /^[0-9A-Fa-f]{1,4}$/.test(g))) return void 0;
26250
- const words3 = [...head, ...back].map((g) => Number.parseInt(g, 16));
26251
- const missing7 = 8 - words3.length - tail2.length;
26260
+ const words2 = [...head, ...back].map((g) => Number.parseInt(g, 16));
26261
+ const missing7 = 8 - words2.length - tail2.length;
26252
26262
  if (halves.length === 2 ? missing7 < 1 : missing7 !== 0) return void 0;
26253
26263
  const all = [
26254
26264
  ...head.map((g) => Number.parseInt(g, 16)),
@@ -32589,21 +32599,26 @@ var PATH_FLAGS = PATH_ONLY | 65536 | 131072;
32589
32599
  var KEYBOARD = /* @__PURE__ */ new Set([SIG.INT, SIG.QUIT, SIG.TSTP]);
32590
32600
  var STUCK_ESCAPES = /* @__PURE__ */ new Set([SIG.INT, SIG.TERM, SIG.QUIT, SIG.HUP]);
32591
32601
  var DEFAULT_UMASK2 = 18;
32592
- function words2(value2) {
32593
- if (!Array.isArray(value2) || !value2.every((w) => typeof w === "string")) {
32594
- throw new KernelError("EINVAL");
32595
- }
32596
- return [...value2];
32597
- }
32598
- var SUDO_ENV_MAX = 4096;
32599
- var SUDO_ENV_BYTES = 1024 * 1024;
32600
- function sudoVariables(value2, term) {
32602
+ var SUDO_VECTOR_MAX = 4096;
32603
+ var SUDO_INPUT_BYTES = 1024 * 1024;
32604
+ function budgetAfterArgs(args) {
32605
+ if (!Array.isArray(args)) throw new KernelError("EINVAL");
32606
+ if (args.length > SUDO_VECTOR_MAX) return -1;
32607
+ let remaining = SUDO_INPUT_BYTES;
32608
+ for (const word of args) {
32609
+ if (typeof word !== "string") throw new KernelError("EINVAL");
32610
+ if (word.length + 1 > remaining) return -1;
32611
+ remaining -= storedSize(word) + 1;
32612
+ if (remaining < 0) return -1;
32613
+ }
32614
+ return remaining;
32615
+ }
32616
+ function sudoVariables(value2, term, budget) {
32601
32617
  const input = typeof value2 === "object" && value2 !== null ? value2 : {};
32602
32618
  const env = /* @__PURE__ */ Object.create(null);
32603
32619
  let count3 = 0;
32604
- let budget = SUDO_ENV_BYTES;
32605
32620
  const fits = (name2, text) => {
32606
- if (++count3 > SUDO_ENV_MAX || name2.length + text.length + 2 > budget) return false;
32621
+ if (++count3 > SUDO_VECTOR_MAX || name2.length + text.length + 2 > budget) return false;
32607
32622
  budget -= storedSize(name2) + storedSize(text) + 2;
32608
32623
  return budget >= 0;
32609
32624
  };
@@ -34652,14 +34667,15 @@ var WasmProcess = class _WasmProcess {
34652
34667
  async sudo(req, cancelled) {
34653
34668
  const { sudo } = this.options;
34654
34669
  if (!sudo) throw new KernelError("ENOSYS");
34655
- const args = words2(req.args);
34670
+ const budget = budgetAfterArgs(req.args);
34671
+ if (budget < 0) return { errno: "E2BIG", error: "sudo: the submitted arguments are too large" };
34656
34672
  const term = typeof req.term === "string" ? req.term : void 0;
34657
- const submitted = sudoVariables(req.env, term);
34673
+ const submitted = sudoVariables(req.env, term, budget);
34658
34674
  if (submitted === void 0)
34659
34675
  return { errno: "E2BIG", error: "sudo: the submitted environment is too large" };
34660
34676
  const call = {
34661
34677
  op: "proc-sudo",
34662
- args,
34678
+ args: [...req.args],
34663
34679
  cwd: typeof req.cwd === "string" && req.cwd.startsWith("/") ? req.cwd : "/",
34664
34680
  ...term !== void 0 ? { term } : {},
34665
34681
  env: submitted
@@ -39331,38 +39347,40 @@ function appendedRoots(given) {
39331
39347
  }
39332
39348
  return [...roots];
39333
39349
  }
39334
- function plainEnv(words3) {
39335
- const next3 = words3[1];
39336
- if (baseName3(words3[0] ?? "") !== "env" || next3 === void 0) return false;
39350
+ function plainEnv(words2) {
39351
+ const next3 = words2[1];
39352
+ if (baseName3(words2[0] ?? "") !== "env" || next3 === void 0) return false;
39337
39353
  return next3 === "-S" || !next3.startsWith("-") && !next3.includes("=");
39338
39354
  }
39339
- function shebangCommand(words3) {
39340
- if (!plainEnv(words3)) {
39341
- const arg2 = words3.slice(1).join(" ");
39342
- return { interp: words3[0], args: arg2 ? [arg2] : [] };
39355
+ function shebangCommand(words2) {
39356
+ if (!plainEnv(words2)) {
39357
+ const arg2 = words2.slice(1).join(" ");
39358
+ return { interp: words2[0], args: arg2 ? [arg2] : [] };
39343
39359
  }
39344
- const split3 = words3[1] === "-S";
39345
- const [interp, ...rest2] = words3.slice(split3 ? 2 : 1);
39360
+ const split3 = words2[1] === "-S";
39361
+ const [interp, ...rest2] = words2.slice(split3 ? 2 : 1);
39346
39362
  const arg = rest2.join(" ");
39347
39363
  return { interp, args: split3 ? rest2 : arg ? [arg] : [] };
39348
39364
  }
39349
39365
  function interpreter(head) {
39350
- const words3 = shebang(head);
39351
- if (!words3) return "node";
39352
- if (baseName3(words3[0]) === "env") words3.shift();
39353
- if (words3[0] === "-S") words3.shift();
39354
- return baseName3(words3[0] ?? "");
39366
+ const words2 = shebang(head);
39367
+ if (!words2) return "node";
39368
+ if (baseName3(words2[0]) === "env") words2.shift();
39369
+ if (words2[0] === "-S") words2.shift();
39370
+ return baseName3(words2[0] ?? "");
39355
39371
  }
39356
39372
  function expandDefaults(defaults2, env) {
39357
39373
  const out = {};
39358
- for (const [key, value2] of Object.entries(defaults2 ?? {})) {
39374
+ for (const [key, entry] of Object.entries(defaults2 ?? {})) {
39359
39375
  let missing7 = false;
39376
+ const value2 = typeof entry === "string" ? entry : entry.value;
39360
39377
  const expanded = value2.replace(ENV_REFERENCE, (_, name2) => {
39361
39378
  const set3 = Object.hasOwn(env, name2) ? env[name2] : void 0;
39362
39379
  if (set3 === void 0) missing7 = true;
39363
39380
  return set3 ?? "";
39364
39381
  });
39365
- if (!missing7) out[key] = expanded;
39382
+ if (missing7) continue;
39383
+ out[key] = typeof entry !== "string" && !expanded.startsWith("/") ? `${entry.pkg}/${expanded.replace(/^\.\//, "")}` : expanded;
39366
39384
  }
39367
39385
  return out;
39368
39386
  }
@@ -39376,7 +39394,7 @@ function targetOf(command, reads) {
39376
39394
  argv0: command.argv0,
39377
39395
  ...command.argv0Fixed ? { fixed: true } : {},
39378
39396
  ...command.args ? { prefix: command.args } : {},
39379
- ...command.env ? { env: command.env } : {},
39397
+ ...command.env ? { env: { ...command.env, ...command.missingEnv } } : {},
39380
39398
  ...command.unset ? { unset: command.unset } : {},
39381
39399
  ...command.imports ? { imports: command.imports } : {},
39382
39400
  ...command.preopenRoot ? { preopenRoot: true } : {},
@@ -39404,7 +39422,7 @@ function withScriptEnv(target, command) {
39404
39422
  if (!command) return target;
39405
39423
  return {
39406
39424
  ...target,
39407
- env: { ...target.env, ...command.env },
39425
+ env: { ...target.env, ...command.env, ...command.missingEnv },
39408
39426
  unset: [
39409
39427
  ...(target.unset ?? []).filter((key) => !Object.hasOwn(command.env ?? {}, key)),
39410
39428
  ...command.unset ?? []
@@ -40289,13 +40307,13 @@ var Launcher = class {
40289
40307
  const named = byPath ? { [script]: this.fs.resolvePath(cwd, file) } : {};
40290
40308
  const head = await this.head(script, who.reads);
40291
40309
  if (!head) return void 0;
40292
- const words3 = await this.interpreterWords(head, script, { ...who, argv: [...argv, file] });
40293
- if (!words3) return void 0;
40294
- const { interp, args } = shebangCommand(words3.words);
40295
- const passed = [...args, command ? script : file, ...words3.kept, ...argv.slice(1)];
40310
+ const words2 = await this.interpreterWords(head, script, { ...who, argv: [...argv, file] });
40311
+ if (!words2) return void 0;
40312
+ const { interp, args } = shebangCommand(words2.words);
40313
+ const passed = [...args, command ? script : file, ...words2.kept, ...argv.slice(1)];
40296
40314
  if (!interp) return void 0;
40297
40315
  who.reads?.operandsFromEnd.set(passed.length - args.length, script);
40298
- who.reads?.interpreters.push([script, ...words3.words, String(words3.kept.length)]);
40316
+ who.reads?.interpreters.push([script, ...words2.words, String(words2.kept.length)]);
40299
40317
  const entry = await this.interpreterFile(interp, cwd, reader, who.pid, who.relative);
40300
40318
  if (!entry) return void 0;
40301
40319
  const { file: walked2, parentHops } = entry;
@@ -40314,7 +40332,7 @@ var Launcher = class {
40314
40332
  const via = [interp, ...inner?.via ?? []];
40315
40333
  const sources = [script, ...inner?.sources ?? []];
40316
40334
  const bins = [...command?.bin ? [script] : [], ...inner?.bins ?? []];
40317
- const chain2 = [...words3.binfmts, ...inner?.binfmts ?? []];
40335
+ const chain2 = [...words2.binfmts, ...inner?.binfmts ?? []];
40318
40336
  return inner && {
40319
40337
  ...inner,
40320
40338
  target: withScriptEnv(inner.target, command),
@@ -40334,7 +40352,7 @@ var Launcher = class {
40334
40352
  walkedVia: [walked2],
40335
40353
  sources: [script],
40336
40354
  ...command?.bin ? { bins: [script] } : {},
40337
- ...words3.binfmts.length > 0 ? { binfmts: words3.binfmts } : {},
40355
+ ...words2.binfmts.length > 0 ? { binfmts: words2.binfmts } : {},
40338
40356
  asked: named
40339
40357
  };
40340
40358
  }