logger: fix potential time_fmt truncation in print_entry_params()

As reported by gcc 9.3.0-10ubuntu2 and
 VERBOSE=1 CMAKE_BUILD_TYPE=Release ./scripts/build-tools.sh -l

  ‘__builtin___snprintf_chk’ output between 23 and 57 bytes
   into a time_fmt destination of size 32

Fixes commit d7b535e282 ("logger: Add option to set timestamp
precision")

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2020-09-15 04:12:21 +00:00 committed by Liam Girdwood
parent 996ffefed4
commit 7d2cb097c2
1 changed files with 5 additions and 1 deletions

View File

@ -360,7 +360,11 @@ static void print_entry_params(const struct log_entry_header *dma_log,
entry->header.line_idx);
} else {
/* timestamp */
if (time_precision >= 0) {
/* 64bits yields less than 20 digits precision. As
* reported by gcc 9.3, this avoids a very long
* precision causing snprintf() to truncate time_fmt
*/
if (time_precision >= 0 && time_precision < 20) {
snprintf(time_fmt, sizeof(time_fmt),
"%%s[%%%d.%df] (%%%d.%df)%%s ",
time_precision + 10, time_precision,