čt 15. 1. 2026 v 18:28 odesílatel Wander Lairson Costa <[email protected]> napsal: > > The parse_ns_duration() function currently uses prefix matching for > detecting time units. This approach is problematic as it silently > accepts malformed strings such as "100nsx" or "100us_invalid" by > ignoring the trailing characters, leading to potential configuration > errors. > > Switch to using strcmp() for suffix comparison to enforce exact matches. > This ensures that the parser strictly validates the time unit and > rejects any input containing invalid trailing characters, thereby > improving the robustness of the configuration parsing. >
Why not use your strncmp_static() helper to protect from overrun? > Signed-off-by: Wander Lairson Costa <[email protected]> > --- > tools/tracing/rtla/src/utils.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c > index 486d96e8290fb..b029fe5970c31 100644 > --- a/tools/tracing/rtla/src/utils.c > +++ b/tools/tracing/rtla/src/utils.c > @@ -211,15 +211,15 @@ long parse_ns_duration(char *val) > t = strtol(val, &end, 10); > > if (end) { > - if (!strncmp(end, "ns", 2)) { > + if (strcmp(end, "ns") == 0) { > return t; > - } else if (!strncmp(end, "us", 2)) { > + } else if (strcmp(end, "us") == 0) { > t *= 1000; > return t; > - } else if (!strncmp(end, "ms", 2)) { > + } else if (strcmp(end, "ms") == 0) { > t *= 1000 * 1000; > return t; > - } else if (!strncmp(end, "s", 1)) { > + } else if (strcmp(end, "s") == 0) { > t *= 1000 * 1000 * 1000; > return t; > } > -- > 2.52.0 > Tomas
