Skip to content

Commit c0289f6

Browse files
shayshyiPaolo Abeni
authored andcommitted
net/mlx5: fw_tracer, Handle escaped percent properly
The firmware tracer's format string validation and parameter counting did not properly handle escaped percent signs (%%). This caused fw_tracer to count more parameters when trace format strings contained literal percent characters. To fix it, allow %% to pass string validation and skip %% sequences when counting parameters since they represent literal percent signs rather than format specifiers. Fixes: 70dd6fd ("net/mlx5: FW tracer, parse traces and kernel tracing support") Signed-off-by: Shay Drory <shayd@nvidia.com> Reported-by: Breno Leitao <leitao@debian.org> Reviewed-by: Moshe Shemesh <moshe@nvidia.com> Closes: https://lore.kernel.org/netdev/hanz6rzrb2bqbplryjrakvkbmv4y5jlmtthnvi3thg5slqvelp@t3s3erottr6s/ Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/1765284977-1363052-5-git-send-email-tariqt@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent b359660 commit c0289f6

File tree

1 file changed

+14
-6
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/diag

1 file changed

+14
-6
lines changed

drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ static bool mlx5_is_valid_spec(const char *str)
368368
while (isdigit(*str) || *str == '#' || *str == '.' || *str == 'l')
369369
str++;
370370

371-
/* Check if it's a valid integer/hex specifier:
371+
/* Check if it's a valid integer/hex specifier or %%:
372372
* Valid formats: %x, %d, %i, %u, etc.
373373
*/
374374
if (*str != 'x' && *str != 'X' && *str != 'd' && *str != 'i' &&
375-
*str != 'u' && *str != 'c')
375+
*str != 'u' && *str != 'c' && *str != '%')
376376
return false;
377377

378378
return true;
@@ -390,7 +390,11 @@ static bool mlx5_tracer_validate_params(const char *str)
390390
if (!mlx5_is_valid_spec(substr + 1))
391391
return false;
392392

393-
substr = strstr(substr + 1, PARAM_CHAR);
393+
if (*(substr + 1) == '%')
394+
substr = strstr(substr + 2, PARAM_CHAR);
395+
else
396+
substr = strstr(substr + 1, PARAM_CHAR);
397+
394398
}
395399

396400
return true;
@@ -469,11 +473,15 @@ static int mlx5_tracer_get_num_of_params(char *str)
469473
substr = strstr(pstr, VAL_PARM);
470474
}
471475

472-
/* count all the % characters */
476+
/* count all the % characters, but skip %% (escaped percent) */
473477
substr = strstr(str, PARAM_CHAR);
474478
while (substr) {
475-
num_of_params += 1;
476-
str = substr + 1;
479+
if (*(substr + 1) != '%') {
480+
num_of_params += 1;
481+
str = substr + 1;
482+
} else {
483+
str = substr + 2;
484+
}
477485
substr = strstr(str, PARAM_CHAR);
478486
}
479487

0 commit comments

Comments
 (0)