From 801289adf2dcb4345031c5c112296f6d376478c4 Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Mon, 20 Jul 2026 12:25:36 +0800 Subject: [PATCH] fix(landlock-run): enforce probe CLI contract --- native/landlock-run/packages/entry/src/main.c | 9 ++++----- native/landlock-run/test/launcher.test.js | 12 +++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/native/landlock-run/packages/entry/src/main.c b/native/landlock-run/packages/entry/src/main.c index 2535f8bc31..af3c2eb3f0 100644 --- a/native/landlock-run/packages/entry/src/main.c +++ b/native/landlock-run/packages/entry/src/main.c @@ -155,6 +155,9 @@ static int parse(int argc, char **argv, struct cli *cli) { while (index < argc) { const char *arg = argv[index]; if (strcmp(arg, "--probe") == 0) { + if (argc != 2) { + return fail_usage("--probe takes no other arguments", NULL); + } cli->probe = 1; index += 1; } else if (strcmp(arg, "--ro") == 0 || strcmp(arg, "--rw") == 0) { @@ -174,11 +177,7 @@ static int parse(int argc, char **argv, struct cli *cli) { return fail_usage("unknown argument: ", arg); } } - if (cli->probe) { - if (cli->ro_count > 0 || cli->rw_count > 0 || (cli->command != NULL && cli->command[0] != NULL)) { - return fail_usage("--probe takes no other arguments", NULL); - } - } else if (cli->command == NULL || cli->command[0] == NULL) { + if (!cli->probe && (cli->command == NULL || cli->command[0] == NULL)) { return fail_usage("missing `-- ...` command", NULL); } return 0; diff --git a/native/landlock-run/test/launcher.test.js b/native/landlock-run/test/launcher.test.js index 4f456e2145..4ab0070e1c 100644 --- a/native/landlock-run/test/launcher.test.js +++ b/native/landlock-run/test/launcher.test.js @@ -53,9 +53,15 @@ const run = (args, options = {}) => spawnSync(launcher, args, { encoding: 'utf8' assert.equal(danglingPath.status, LAUNCHER_FAILURE_EXIT); assert.match(danglingPath.stderr, /--ro requires a path/); - const probeWithExtras = run(['--probe', '--ro', '/']); - assert.equal(probeWithExtras.status, LAUNCHER_FAILURE_EXIT); - assert.match(probeWithExtras.stderr, /--probe takes no other arguments/); + for (const args of [ + ['--probe', '--ro', '/'], + ['--probe', '--'], + ['--probe', '--probe'], + ]) { + const probeWithExtras = run(args); + assert.equal(probeWithExtras.status, LAUNCHER_FAILURE_EXIT); + assert.match(probeWithExtras.stderr, /--probe takes no other arguments/); + } } // --- probe: the functional availability signal ---