Skip to content

Commit 1bbaa92

Browse files
authored
log: fix potential overflow with long log messages (#490)
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 't->max_line_length' as the maximum length of the formatted log message to limit space to the actual bytes left Also added error checks to the blackbox calls at the end of the test, as these now provide a proper test that the BB is functioning. Before they were masking failures.
1 parent 92ddd7c commit 1bbaa92

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/log_blackbox.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ _blackbox_vlogger(int32_t target,
110110
chunk += sizeof(uint32_t);
111111

112112
/* log message */
113-
msg_len = qb_vsnprintf_serialize(chunk, max_size, cs->format, ap);
114-
if (msg_len >= max_size) {
113+
msg_len = qb_vsnprintf_serialize(chunk, t->max_line_length, cs->format, ap);
114+
if (msg_len >= t->max_line_length) {
115115
chunk = msg_len_pt + sizeof(uint32_t); /* Reset */
116116

117117
/* Leave this at QB_LOG_MAX_LEN so as not to overflow the blackbox */

tests/check_log.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,10 @@ START_TEST(test_log_long_msg)
832832
qb_log(LOG_INFO, "Message %d %d - %s", lpc, lpc%600, buffer);
833833
}
834834

835-
qb_log_blackbox_write_to_file("blackbox.dump");
836-
qb_log_blackbox_print_from_file("blackbox.dump");
835+
rc = qb_log_blackbox_write_to_file("blackbox.dump");
836+
ck_assert_int_gt(rc, 0);
837+
rc = qb_log_blackbox_print_from_file("blackbox.dump");
838+
ck_assert_int_le(rc, 0);
837839
unlink("blackbox.dump");
838840
qb_log_fini();
839841
}

0 commit comments

Comments
 (0)