Skip to content

Commit

Permalink
broker: avoid truncation of log messages during shutdown
Browse files Browse the repository at this point in the history
Problem: In the broker shutdown code, log messages may be
truncated because the log forwarding code uses a static buffer of
FLUX_MAX_LOGBUF.

Since a maximum size of the final log message is known, use a
variable length array for the buffer in forward_logbuf() instead
of FLUX_MAX_LOGBUF to avoid any truncation.
  • Loading branch information
grondo committed Jan 14, 2025
1 parent d0aef26 commit 318b9ba
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/broker/shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,14 @@ static int forward_logbuf (flux_t *h,
struct stdlog_header hdr;
const char *txt;
size_t txtlen;
char buf[FLUX_MAX_LOGBUF];
int len = strlen (stdlog);
char buf[len + 1];
int loglevel;

if (flux_msg_unpack (request, "{s:i}", "loglevel", &loglevel) < 0)
loglevel = LOG_ERR;

if (stdlog_decode (stdlog,
strlen (stdlog),
&hdr,
NULL,
NULL,
&txt,
&txtlen) < 0
if (stdlog_decode (stdlog, len, &hdr, NULL, NULL, &txt, &txtlen) < 0
|| STDLOG_SEVERITY (hdr.pri) > loglevel
|| snprintf (buf,
sizeof (buf),
Expand Down

0 comments on commit 318b9ba

Please sign in to comment.