linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Cc: Yordan Karadzhov <y.karadz@gmail.com>,
	Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH v4 04/10] libtracefs: Change tracefs_kprobe_info API
Date: Thu, 4 Nov 2021 13:57:11 -0400	[thread overview]
Message-ID: <20211104135711.6ab8826c@gandalf.local.home> (raw)
In-Reply-To: <CAPpZLN48XgUnpAc+m7bTevqzYHZC=LjResC026_Hfr9veKegWQ@mail.gmail.com>

On Thu, 4 Nov 2021 19:28:49 +0200
Tzvetomir Stoyanov <tz.stoyanov@gmail.com> wrote:

> On Thu, Nov 4, 2021 at 6:33 PM Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > On Thu,  4 Nov 2021 13:10:41 +0200
> > "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
> >  
> > > +enum tracefs_dynevent_type tracefs_kprobe_info(struct tracefs_dynevent *kprobe,
> > > +                                            char **system, char **event,
> > > +                                            char **prefix, char **addr, char **format)
> > > +{
> > > +     char **lv[] = { system, event, prefix, addr, format };
> > > +     char **rv[] = { &kprobe->system, &kprobe->event, &kprobe->prefix,
> > > +                     &kprobe->address, &kprobe->format };
> > > +     int i;
> > > +
> > > +     if (!kprobe)
> > > +             return TRACEFS_DYNEVENT_MAX;
> > > +
> > > +     for (i = 0; i < ARRAY_SIZE(lv); i++)
> > > +             *lv[i] = NULL;  
> >
> > Do we really need to initialize them to NULL here?
> >
> > Not to mention, if one of the parameters is NULL itself, this will SEGFAULT.
> >  
> 
> I'll add a check for that. They should be set to NULL to ensure that
> free() in the error path will not segfault, if the caller passes not
> initialised pointers.

It wont, due to the fact that it starts at i and works backward down to
zero. The only items it will look at are the ones that were already
initialized. Which is why I did it that way.

> 
> > > +
> > > +     for (i = 0; i < ARRAY_SIZE(lv); i++) {  
> >
> > Nice use of ARRAY_SIZE() ;-)
> >  
> > > +             if (lv[i]) {
> > > +                     if (*rv[i]) {
> > > +                             *lv[i] = strdup(*rv[i]);
> > > +                             if (!*lv[i])
> > > +                                     goto error;
> > > +                     } else {
> > > +                             *lv[i] = NULL;
> > >                       }  

> > > +
> > > +     return kprobe->type;
> > > +
> > > +error:
> > > +     for (i--; i >= 0; i--) {

The above means that we do not need to initialize anything that wasn't
touched.

-- Steve


> > > +             if (lv[i])
> > > +                     free(*lv[i]);
> > > +     }
> > > +
> > > +     return TRACEFS_DYNEVENT_MAX;
> > >  }  
> >  
> 
> 


  reply	other threads:[~2021-11-04 17:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 11:10 [PATCH v4 00/10] libtracefs dynamic events support Tzvetomir Stoyanov (VMware)
2021-11-04 11:10 ` [PATCH v4 01/10] libtracefs: New APIs for dynamic events Tzvetomir Stoyanov (VMware)
2021-11-04 13:58   ` Steven Rostedt
2021-11-04 14:37   ` Steven Rostedt
2021-11-04 14:54   ` Steven Rostedt
2021-11-04 11:10 ` [PATCH v4 02/10] libtracefs: New APIs for kprobe allocation Tzvetomir Stoyanov (VMware)
2021-11-04 16:29   ` Steven Rostedt
2021-11-04 11:10 ` [PATCH v4 03/10] libtracefs: Remove redundant kprobes APIs Tzvetomir Stoyanov (VMware)
2021-11-04 11:10 ` [PATCH v4 04/10] libtracefs: Change tracefs_kprobe_info API Tzvetomir Stoyanov (VMware)
2021-11-04 16:33   ` Steven Rostedt
2021-11-04 17:28     ` Tzvetomir Stoyanov
2021-11-04 17:57       ` Steven Rostedt [this message]
2021-11-04 11:10 ` [PATCH v4 05/10] libtracefs: Reimplement kprobe raw APIs Tzvetomir Stoyanov (VMware)
2021-11-04 11:10 ` [PATCH v4 06/10] libtracefs: Extend kprobes unit test Tzvetomir Stoyanov (VMware)
2021-11-04 11:10 ` [PATCH v4 07/10] libtracefs: Rename tracefs_synth_init API Tzvetomir Stoyanov (VMware)
2021-11-04 11:10 ` [PATCH v4 08/10] libtracefs: Use the internal dynamic events API when creating synthetic events Tzvetomir Stoyanov (VMware)
2021-11-04 12:47   ` Yordan Karadzhov
2021-11-04 13:21     ` Steven Rostedt
2021-11-04 17:13   ` Steven Rostedt
2021-11-05 12:15     ` Tzvetomir Stoyanov
2021-11-05 12:33       ` Steven Rostedt
2021-11-04 11:10 ` [PATCH v4 09/10] libtracefs: Update kprobes man pages Tzvetomir Stoyanov (VMware)
2021-11-04 20:28   ` Steven Rostedt
2021-11-04 11:10 ` [PATCH v4 10/10] libtracefs: Document dynamic events APIs Tzvetomir Stoyanov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211104135711.6ab8826c@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    --cc=y.karadz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).