Re: [PATCH v3 12/18] rtla: Enforce exact match for time unit suffixes
From: Wander Lairson Costa
Date: Mon Mar 09 2026 - 13:18:19 EST
On Tue, Mar 03, 2026 at 03:27:35PM +0100, Tomas Glozar wrote:
> čt 15. 1. 2026 v 18:28 odesílatel Wander Lairson Costa
> <wander@xxxxxxxxxx> 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?
As I said before, sometime I fail to follow my own rules *facepalm*.
>
> > Signed-off-by: Wander Lairson Costa <wander@xxxxxxxxxx>
> > ---
> > 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
>