Skip to content

Commit d071475

Browse files
committed
Prevent using --list-rules and --list-vars together
There's no check preventing `--list-rules` and `--list-vars` from being passed simultaneously. If both are set, `--list_rules` wins silently because of the `if/else if` chain. We will print an error message in this situation.
1 parent 995c217 commit d071475

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

tests/API/XCCDF/unittests/test_list_vars.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ grep -q "\-\-list-vars option requires \-\-profile" $stderr
2525
:> $stdout
2626
:> $stderr
2727

28+
# Test 3: --list-vars with --list-rules produces an error
29+
$OSCAP info --profile $p1 --list-vars --list-rules $ds > $stdout 2> $stderr && exit 1 || true
30+
grep -q "The \-\-list-rules and \-\-list-vars options can't be used at the same time." $stderr
31+
:> $stdout
32+
:> $stderr
33+
2834
rm -f $stdout $stderr

utils/oscap-info.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,11 @@ bool getopt_info(int argc, char **argv, struct oscap_action *action)
923923
return false;
924924
}
925925

926+
if (action->list_rules && action->list_vars) {
927+
oscap_module_usage(action->module, stderr, "The --list-rules and --list-vars options can't be used at the same time.\n");
928+
return false;
929+
}
930+
926931
if (optind >= argc) {
927932
oscap_module_usage(action->module, stderr, "SCAP file needs to be specified!\n");
928933
return false;

0 commit comments

Comments
 (0)