-
Notifications
You must be signed in to change notification settings - Fork 438
XCCDF/OVAL/CPE/DS: fix NULL-pointer dereferences on malformed input #2361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1453,7 +1453,8 @@ static struct xccdf_score *xccdf_score_new_parse(xmlTextReaderPtr reader) | |
| if (xccdf_attribute_has(reader, XCCDFA_MAXIMUM)) | ||
| score->maximum = xccdf_attribute_get_float(reader, XCCDFA_MAXIMUM); | ||
| else score->maximum = XCCDF_SCORE_MAX_DAFAULT; | ||
| score->score = atof(oscap_element_string_get(reader)); | ||
| const char *score_str = oscap_element_string_get(reader); | ||
| score->score = score_str ? atof(score_str) : 0.0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like might be better here. if (score_str == NULL) {
dW("Empty <score> element is invalid, rejecting.");
xccdf_score_free(score);
return NULL;
}
score->score = atof(score_str); |
||
| return score; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,13 +144,15 @@ struct xccdf_item *xccdf_value_parse(xmlTextReaderPtr reader, struct xccdf_item | |
| case XCCDFE_LOWER_BOUND: | ||
| if (type == XCCDF_TYPE_NUMBER) { | ||
| val = _xccdf_value_find_or_create_instance(XVALUE(value), selector, type); | ||
| val->lower_bound = atof(oscap_element_string_get(reader)); | ||
| const char *lb = oscap_element_string_get(reader); | ||
| val->lower_bound = lb ? atof(lb) : 0.0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaulting 0.0 might not be right thing here. Something like below might be better. if (lb == NULL) {
dW("Empty <lower-bound> element is invalid, rejecting <Value>.");
xccdf_value_free(value);
return NULL;
}
val = _xccdf_value_find_or_create_instance(XVALUE(value), selector, type);
val->lower_bound = atof(lb);
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I wasn't sure if it was preferable to default or to fail. sounds good to me :) |
||
| } | ||
| break; | ||
| case XCCDFE_UPPER_BOUND: | ||
| if (type == XCCDF_TYPE_NUMBER) { | ||
| val = _xccdf_value_find_or_create_instance(XVALUE(value), selector, type); | ||
| val->upper_bound = atof(oscap_element_string_get(reader)); | ||
| const char *ub = oscap_element_string_get(reader); | ||
| val->upper_bound = ub ? atof(ub) : 0.0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as lower bound. Something like const char *ub = oscap_element_string_get(reader);
if (ub == NULL) {
dW("Empty <upper-bound> element is invalid, rejecting <Value>.");
xccdf_value_free(value);
return NULL;
}
val = _xccdf_value_find_or_create_instance(XVALUE(value), selector, type);
val->upper_bound = atof(ub); |
||
| } | ||
| break; | ||
| case XCCDFE_CHOICES: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be placed before line 457?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, yep, thanks 😅 (fixed in 906022e)