Skip to content
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

log: fix potential overflow with long log messages #490

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

chrissie-c
Copy link
Contributor

qb_vsnprintf_serialize was called with 'max_size' as the limiting number for the length of the formatted log message. But the buffer also needs to contain the
log header (given by 'actual_size'), so we now pass 'max_size - actual_size' as the maximum length of the formatted log message.

Also added error checks to the blacbkbox calls at
the end of the test, as these now provide a proper test that the BB is functioning. Before they were
masking failures.

Copy link
Member

@jfriesse jfriesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, really good catch.

qb_vsnprintf_serialize was called with 'max_size' as the
limiting number for the length of the formatted log
message. But the buffer also needs to contain the
log header (given by 'actual_size'), so we now pass
'max_size - actual_size' as the maximum length of the
formatted log message.

Also added error checks to the blacbkbox calls at
the end of the test, as these now provide a proper
test that the BB is functioning. Before they were
masking failures.
Copy link
Member

@jfriesse jfriesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK^2 :)

@chrissie-c chrissie-c merged commit 1bbaa92 into ClusterLabs:main Jul 20, 2023
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Jul 26, 2023
https://build.opensuse.org/request/show/1100598
by user yan_gao + anag+factory
- Update to version 2.0.8+20230721.002171b (v2.0.8):
- log: fix potential overflow with long log messages (gh#ClusterLabs/libqb#490) (forwarded request 1100597 from yan_gao)
msg_len = qb_vsnprintf_serialize(chunk, max_size, cs->format, ap);
if (msg_len >= max_size) {
msg_len = qb_vsnprintf_serialize(chunk, t->max_line_length, cs->format, ap);
if (msg_len >= t->max_line_length) {
chunk = msg_len_pt + sizeof(uint32_t); /* Reset */

/* Leave this at QB_LOG_MAX_LEN so as not to overflow the blackbox */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the next line could theoretically be a problem if the caller used QB_LOG_CONF_MAX_LINE_LEN to set the max line length below the length of the "too long" message. (I wouldn't consider it a security issue since the message is hardcoded, not to mention it would be bizarre for a caller to do that). In any case, the "too long" message isn't really helpful -- why not just use as much of the long message as possible (maybe replacing the last three usable characters with an ellipsis)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for replacing "too long" message with shortened version of logged message. Also I think it may make sense to check QB_LOG_CONF_MAX_LINE_LEN for some minimal reasonable length (right now only maximum length of QB_LOG_ABSOLUTE_MAX_LEN is checked)

@chrissie-c
Copy link
Contributor Author

chrissie-c commented Aug 16, 2023

The ellipsis code has been in there for ages, but it needs to be enabled:

    rc = qb_log_ctl(t, QB_LOG_CONF_ELLIPSIS, QB_TRUE);

0ec02f9

@kgaillot
Copy link
Contributor

The ellipsis code has been in there for ages, but it needs to be enabled:

    rc = qb_log_ctl(t, QB_LOG_CONF_ELLIPSIS, QB_TRUE);

0ec02f9

log_blackbox.c doesn't use qb_log_target_format() (I'm not familiar enough with the code to know why not), so the ellipsis code isn't hit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants