Skip to content

Commit

Permalink
job: truncate unit description
Browse files Browse the repository at this point in the history
The comment above says we're truncating the string but that's not true,
an assert will fail in xsprintf if the description is longer than
LINE_MAX.

Let's use snprintf instead of xsprintf to make sure it's truncated.
We'll cast its result to void to tell static checkers we're fine with
truncation.
  • Loading branch information
iaguis authored and poettering committed Feb 19, 2018
1 parent 9371f85 commit 574432f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/job.c
Expand Up @@ -776,9 +776,12 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
if (!format)
return;

/* The description might be longer than the buffer, but that's OK, we'll just truncate it here */
/* The description might be longer than the buffer, but that's OK,
* we'll just truncate it here. Note that we use snprintf() rather than
* xsprintf() on purpose here: we are fine with truncation and don't
* consider that an error. */
DISABLE_WARNING_FORMAT_NONLITERAL;
xsprintf(buf, format, unit_description(u));
(void) snprintf(buf, sizeof(buf), format, unit_description(u));
REENABLE_WARNING;

switch (t) {
Expand Down

0 comments on commit 574432f

Please sign in to comment.