Skip to content

Commit

Permalink
utils: Perform Schematron validation only if XSD validation succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyz committed Apr 15, 2021
1 parent 7df8abc commit e17cb56
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 43 deletions.
37 changes: 15 additions & 22 deletions utils/oscap-oval.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,37 +754,30 @@ static bool valid_inputs(const struct oscap_action *action) {

static int app_oval_validate(const struct oscap_action *action) {
int ret;
int result = OSCAP_ERROR;
int result = OSCAP_OK;

struct oscap_source *source = oscap_source_new_from_file(action->f_oval);
ret = oscap_source_validate(source, reporter, (void *) action);
if (ret == -1) {
result = OSCAP_ERROR;
goto cleanup;
}
else {
result = ret == 1 ? OSCAP_FAIL : OSCAP_OK;
}

/* schematron-based validation requested
We can only do schematron validation if the file isn't a source datastream
*/
if (action->schematron && oscap_source_get_scap_type(source) != OSCAP_DOCUMENT_SDS) {
ret = oscap_source_validate_schematron(source, NULL);
if (ret==-1) {
result=OSCAP_ERROR;
}
else if (ret>0) {
result=OSCAP_FAIL;
if (ret < 0) {
result = OSCAP_ERROR;
} else if (ret > 0) {
result = OSCAP_FAIL;
} else {
// We can only do schematron validation if the file isn't a source datastream
if (action->schematron && oscap_source_get_scap_type(source) != OSCAP_DOCUMENT_SDS) {
ret = oscap_source_validate_schematron(source, NULL);
if (ret < 0) {
result = OSCAP_ERROR;
} else if (ret > 0) {
result = OSCAP_FAIL;
}
}
}

cleanup:
oscap_source_free(source);
if (oscap_err())
fprintf(stderr, "%s %s\n", OSCAP_ERR_MSG, oscap_err_desc());
oscap_print_error();

return result;

}

36 changes: 15 additions & 21 deletions utils/oscap-xccdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,34 +1251,28 @@ bool getopt_xccdf(int argc, char **argv, struct oscap_action *action)

int app_xccdf_validate(const struct oscap_action *action) {
int ret;
int result;

int result = OSCAP_OK;

struct oscap_source *source = oscap_source_new_from_file(action->f_xccdf);
ret = oscap_source_validate(source, reporter, (void *) action);
if (ret==-1) {
result=OSCAP_ERROR;
goto cleanup;
}
else if (ret==1) {
result=OSCAP_FAIL;
}
else
result=OSCAP_OK;

if (action->schematron) {
ret = oscap_source_validate_schematron(source, NULL);
if (ret == -1) {
result = OSCAP_ERROR;
} else if (ret > 0) {
result = OSCAP_FAIL;

if (ret < 0) {
result = OSCAP_ERROR;
} else if (ret > 0) {
result = OSCAP_FAIL;
} else {
if (action->schematron) {
ret = oscap_source_validate_schematron(source, NULL);
if (ret < 0) {
result = OSCAP_ERROR;
} else if (ret > 0) {
result = OSCAP_FAIL;
}
}
}

cleanup:
oscap_source_free(source);
oscap_print_error();

return result;

return result;
}

0 comments on commit e17cb56

Please sign in to comment.