[3/8] trace: fix leak with regexp
Checks
Commit Message
The precompiled buffer initialised in regcomp must be freed before
leaving rte_trace_regexp.
Fixes: 84c4fae4628f ("trace: implement operation APIs")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
lib/eal/common/eal_common_trace.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
Comments
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Wednesday, September 21, 2022 5:34 PM
> To: dev@dpdk.org
> Cc: stable@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>; Sunil
> Kumar Kori <skori@marvell.com>
> Subject: [EXT] [PATCH 3/8] trace: fix leak with regexp
>
> External Email
>
> ----------------------------------------------------------------------
> The precompiled buffer initialised in regcomp must be freed before leaving
> rte_trace_regexp.
>
> Fixes: 84c4fae4628f ("trace: implement operation APIs")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
> lib/eal/common/eal_common_trace.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/lib/eal/common/eal_common_trace.c
> b/lib/eal/common/eal_common_trace.c
> index 1db28a441d..c835b0d16e 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c
> @@ -210,15 +210,18 @@ rte_trace_regexp(const char *regex, bool enable)
> return -EINVAL;
>
> STAILQ_FOREACH(tp, &tp_list, next) {
> - if (regexec(&r, tp->name, 0, NULL, 0) == 0) {
> - if (enable)
> - rc = rte_trace_point_enable(tp->handle);
> - else
> - rc = rte_trace_point_disable(tp->handle);
> - found = 1;
> + if (regexec(&r, tp->name, 0, NULL, 0) != 0)
> + continue;
> +
> + if (enable)
> + rc = rte_trace_point_enable(tp->handle);
> + else
> + rc = rte_trace_point_disable(tp->handle);
> + if (rc < 0) {
> + found = 0;
> + break;
> }
> - if (rc < 0)
> - return rc;
> + found = 1;
> }
> regfree(&r);
>
> --
I understand the problem addressed by this fix but may be following changes will be sufficient to fix it.
Please highlight, If I am missing. Just trying to reduce the line of changes.
@@ -220,8 +220,10 @@ rte_trace_regexp(const char *regex, bool enable)
rc = rte_trace_point_disable(tp->handle);
found = 1;
}
- if (rc < 0)
- return rc;
+ if (rc < 0) {
+ found = 0;
+ break;
+ }
}
> 2.37.3
On Thu, Sep 22, 2022 at 1:00 PM Sunil Kumar Kori <skori@marvell.com> wrote:
> > @@ -210,15 +210,18 @@ rte_trace_regexp(const char *regex, bool enable)
> > return -EINVAL;
> >
> > STAILQ_FOREACH(tp, &tp_list, next) {
> > - if (regexec(&r, tp->name, 0, NULL, 0) == 0) {
> > - if (enable)
> > - rc = rte_trace_point_enable(tp->handle);
> > - else
> > - rc = rte_trace_point_disable(tp->handle);
> > - found = 1;
> > + if (regexec(&r, tp->name, 0, NULL, 0) != 0)
> > + continue;
> > +
> > + if (enable)
> > + rc = rte_trace_point_enable(tp->handle);
> > + else
> > + rc = rte_trace_point_disable(tp->handle);
> > + if (rc < 0) {
> > + found = 0;
> > + break;
> > }
> > - if (rc < 0)
> > - return rc;
> > + found = 1;
> > }
> > regfree(&r);
> >
> > --
>
> I understand the problem addressed by this fix but may be following changes will be sufficient to fix it.
> Please highlight, If I am missing. Just trying to reduce the line of changes.
>
> @@ -220,8 +220,10 @@ rte_trace_regexp(const char *regex, bool enable)
> rc = rte_trace_point_disable(tp->handle);
> found = 1;
> }
> - if (rc < 0)
> - return rc;
> + if (rc < 0) {
> + found = 0;
> + break;
> + }
> }
rc is compared against 0 for all non-matching tracepoints.
This is unnecessary and fragile.
I can split this change in two: one for the fix, and one other where
the loop is updated with a continue and an inverted matching condition
like above.
If going like this, I would update rte_trace_pattern() too, in the second patch.
WDYT?
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, September 23, 2022 12:05 PM
> To: Sunil Kumar Kori <skori@marvell.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Jerin Jacob Kollanukkaran
> <jerinj@marvell.com>
> Subject: Re: [EXT] [PATCH 3/8] trace: fix leak with regexp
>
> On Thu, Sep 22, 2022 at 1:00 PM Sunil Kumar Kori <skori@marvell.com>
> wrote:
> > > @@ -210,15 +210,18 @@ rte_trace_regexp(const char *regex, bool
> enable)
> > > return -EINVAL;
> > >
> > > STAILQ_FOREACH(tp, &tp_list, next) {
> > > - if (regexec(&r, tp->name, 0, NULL, 0) == 0) {
> > > - if (enable)
> > > - rc = rte_trace_point_enable(tp->handle);
> > > - else
> > > - rc = rte_trace_point_disable(tp->handle);
> > > - found = 1;
> > > + if (regexec(&r, tp->name, 0, NULL, 0) != 0)
> > > + continue;
> > > +
> > > + if (enable)
> > > + rc = rte_trace_point_enable(tp->handle);
> > > + else
> > > + rc = rte_trace_point_disable(tp->handle);
> > > + if (rc < 0) {
> > > + found = 0;
> > > + break;
> > > }
> > > - if (rc < 0)
> > > - return rc;
> > > + found = 1;
> > > }
> > > regfree(&r);
> > >
> > > --
> >
> > I understand the problem addressed by this fix but may be following
> changes will be sufficient to fix it.
> > Please highlight, If I am missing. Just trying to reduce the line of changes.
> >
> > @@ -220,8 +220,10 @@ rte_trace_regexp(const char *regex, bool enable)
> > rc = rte_trace_point_disable(tp->handle);
> > found = 1;
> > }
> > - if (rc < 0)
> > - return rc;
> > + if (rc < 0) {
> > + found = 0;
> > + break;
> > + }
> > }
>
>
> rc is compared against 0 for all non-matching tracepoints.
> This is unnecessary and fragile.
>
> I can split this change in two: one for the fix, and one other where the loop is
> updated with a continue and an inverted matching condition like above.
> If going like this, I would update rte_trace_pattern() too, in the second patch.
>
> WDYT?
Sounds okay. You can proceed in either way. No hard opinion on it.
>
>
> --
> David Marchand
@@ -210,15 +210,18 @@ rte_trace_regexp(const char *regex, bool enable)
return -EINVAL;
STAILQ_FOREACH(tp, &tp_list, next) {
- if (regexec(&r, tp->name, 0, NULL, 0) == 0) {
- if (enable)
- rc = rte_trace_point_enable(tp->handle);
- else
- rc = rte_trace_point_disable(tp->handle);
- found = 1;
+ if (regexec(&r, tp->name, 0, NULL, 0) != 0)
+ continue;
+
+ if (enable)
+ rc = rte_trace_point_enable(tp->handle);
+ else
+ rc = rte_trace_point_disable(tp->handle);
+ if (rc < 0) {
+ found = 0;
+ break;
}
- if (rc < 0)
- return rc;
+ found = 1;
}
regfree(&r);