Fix verbose command line option#2220
Conversation
This commit ensures that the `--verbose` and `--verbose-log-file` options can be provided at any position on the command line and that they can be mixed between other options. Addressing: $ oscap xccdf eval --profile ospp --verbose DEVEL /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml oscap: unrecognized option '--verbose' Fixes: https://issues.redhat.com/browse/RHEL-53859
e3fbed6 to
3d818e5
Compare
| local RF="results.xml" | ||
| local LOG="verbose.log" | ||
|
|
||
| $OSCAP xccdf --verbose=DEVEL eval --fetch-remote-resources --results $RF $DF 2>$LOG || echo "OK" |
There was a problem hiding this comment.
Does the new option parsing mechanism fail for this option position? If not, why did you change it?
There was a problem hiding this comment.
Yes, it now fails if the --verbose is between module and submodule name. Is it fine? The reason seems to be that the verbose options are now options of each submodule and not global options.
There was a problem hiding this comment.
This is a backward-incompatible change.
utils/oscap-info.c
Outdated
| @@ -776,19 +790,25 @@ bool getopt_info(int argc, char **argv, struct oscap_action *action) | |||
| while ((c = getopt_long(argc, argv, "o:i:p:", long_options, NULL)) != -1) { | |||
There was a problem hiding this comment.
Do we still accept short options?
There was a problem hiding this comment.
Do you mean here in oscap info module? The oscap info doesn't have any short options so I think we don't accept them.
There was a problem hiding this comment.
Should the "o:i:p:" here be removed?
There was a problem hiding this comment.
Probably. They won't work with your changes anyway.
The `optstring` parameter in `getopt_long` call in `oscap info` submodule parser specifies some short options. However, the `oscap info` submodule doesn't support any short options. It only supports long options. Therefore, these characters in the `optstring` parameter are superfluous and should be removed.
|
I have removed them from the optstring and I have prevented the backward incompatible changes. |
| if (optind >= argc) { | ||
| return oscap_module_usage(action->module, stderr, "Wrong number of arguments!\n"); | ||
| } | ||
| action->cpe_action = malloc(sizeof(struct cpe_action)); |
There was a problem hiding this comment.
OpenScanHub reports several warnings around this allocation:
Error: GCC_ANALYZER_WARNING (CWE-476): [#def4]
openscap-1.4.3-build/openscap-1.4.3/utils/oscap-cpe.c: scope_hint: In function ‘getopt_cpe’
openscap-1.4.3-build/openscap-1.4.3/utils/oscap-cpe.c:134:42: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘*action.cpe_action’
# 132| action->cpe_action = malloc(sizeof(struct cpe_action));
# 133| if (action->module == &CPE_MATCH_MODULE) {
# 134|-> action->cpe_action->name = argv[optind];
# 135| action->cpe_action->dict = argv[optind + 1];
# 136| }
Error: GCC_ANALYZER_WARNING (CWE-476): [#def5]
openscap-1.4.3-build/openscap-1.4.3/utils/oscap-cpe.c:138:42: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘*action.cpe_action’
# 136| }
# 137| if (action->module == &CPE_CHECK_MODULE) {
# 138|-> action->cpe_action->name = argv[optind];
# 139| }
# 140| if (action->module == &CPE_VALIDATE) {
Error: GCC_ANALYZER_WARNING (CWE-476): [#def6]
openscap-1.4.3-build/openscap-1.4.3/utils/oscap-cpe.c:141:42: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘*action.cpe_action’
# 139| }
# 140| if (action->module == &CPE_VALIDATE) {
# 141|-> action->cpe_action->dict = argv[optind];
# 142| }
# 143| return true;
Please feel free to fix them if they may be real issues. Thanks!
|
I have add ensure cpe_action is not NULL |
This commit ensures that the
--verboseand--verbose-log-fileoptions can be provided at any position on the command line and that they can be mixed between other options.Addressing:
$ oscap xccdf eval --profile ospp --verbose DEVEL /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml oscap: unrecognized option '--verbose'
Fixes: https://issues.redhat.com/browse/RHEL-53859