fix(landlock-run): enforce probe CLI contract
This commit is contained in:
@@ -155,6 +155,9 @@ static int parse(int argc, char **argv, struct cli *cli) {
|
|||||||
while (index < argc) {
|
while (index < argc) {
|
||||||
const char *arg = argv[index];
|
const char *arg = argv[index];
|
||||||
if (strcmp(arg, "--probe") == 0) {
|
if (strcmp(arg, "--probe") == 0) {
|
||||||
|
if (argc != 2) {
|
||||||
|
return fail_usage("--probe takes no other arguments", NULL);
|
||||||
|
}
|
||||||
cli->probe = 1;
|
cli->probe = 1;
|
||||||
index += 1;
|
index += 1;
|
||||||
} else if (strcmp(arg, "--ro") == 0 || strcmp(arg, "--rw") == 0) {
|
} 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);
|
return fail_usage("unknown argument: ", arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cli->probe) {
|
if (!cli->probe && (cli->command == NULL || cli->command[0] == NULL)) {
|
||||||
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) {
|
|
||||||
return fail_usage("missing `-- <argv>...` command", NULL);
|
return fail_usage("missing `-- <argv>...` command", NULL);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -53,9 +53,15 @@ const run = (args, options = {}) => spawnSync(launcher, args, { encoding: 'utf8'
|
|||||||
assert.equal(danglingPath.status, LAUNCHER_FAILURE_EXIT);
|
assert.equal(danglingPath.status, LAUNCHER_FAILURE_EXIT);
|
||||||
assert.match(danglingPath.stderr, /--ro requires a path/);
|
assert.match(danglingPath.stderr, /--ro requires a path/);
|
||||||
|
|
||||||
const probeWithExtras = run(['--probe', '--ro', '/']);
|
for (const args of [
|
||||||
assert.equal(probeWithExtras.status, LAUNCHER_FAILURE_EXIT);
|
['--probe', '--ro', '/'],
|
||||||
assert.match(probeWithExtras.stderr, /--probe takes no other arguments/);
|
['--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 ---
|
// --- probe: the functional availability signal ---
|
||||||
|
|||||||
Reference in New Issue
Block a user