From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9669FC05027 for ; Mon, 20 Feb 2023 01:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbjBTB4U convert rfc822-to-8bit (ORCPT ); Sun, 19 Feb 2023 20:56:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjBTB4Q (ORCPT ); Sun, 19 Feb 2023 20:56:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C039A25C; Sun, 19 Feb 2023 17:56:15 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AB624B80AC6; Mon, 20 Feb 2023 01:56:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43FA0C433D2; Mon, 20 Feb 2023 01:56:11 +0000 (UTC) Date: Sun, 19 Feb 2023 20:56:08 -0500 From: Steven Rostedt To: Tom Zanussi Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , ionut_n2001@yahoo.com Subject: Re: [PATCH] tracing: Check for NULL field_name in __synth_event_add_val() Message-ID: <20230219205608.4664c310@rorschach.local.home> In-Reply-To: <06c77bca76cd5679c8cd459480621b7db21f3a7b.camel@kernel.org> References: <20230218105921.12ddb86f@gandalf.local.home> <06c77bca76cd5679c8cd459480621b7db21f3a7b.camel@kernel.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 19 Feb 2023 15:46:24 -0600 Tom Zanussi wrote: > No, because this code just above it makes sure you can't mix add_name > with add_next. Once add_name is set it will return -EINVAL if > field_name is ever null after that, and add_name will never be changed > once set: > > /* can't mix add_next_synth_val() with add_synth_val() */ > if (field_name) { > if (trace_state->add_next) { > ret = -EINVAL; > goto out; > } > trace_state->add_name = true; > } else { > if (trace_state->add_name) { > ret = -EINVAL; > goto out; > } > trace_state->add_next = true; > } > > > >  kernel/trace/trace_events_synth.c | 4 ++++ > >  1 file changed, 4 insertions(+) > > > > diff --git a/kernel/trace/trace_events_synth.c > > b/kernel/trace/trace_events_synth.c > > index 70bddb25d9c0..fa28c1da06d2 100644 > > --- a/kernel/trace/trace_events_synth.c > > +++ b/kernel/trace/trace_events_synth.c > > @@ -1982,6 +1982,10 @@ static int __synth_event_add_val(const char > > *field_name, u64 val, > >   > >         event = trace_state->event; > >         if (trace_state->add_name) { > > +               if (!field_name) { > > +                       ret = -EINVAL; > > +                       goto out; > > +               } > > So if add_name is set here, it must also mean that field_name can't be > null, because of the above. > > >                 for (i = 0; i < event->n_fields; i++) { > >                         field = event->fields[i]; > >                         if (strcmp(field->name, field_name) == 0) > > And if field_name can't be null, then I don't see how this strcmp could > fail due to a null field_name. > > So I don't see the need for this patch. The bugzilla shows a compiler > warning when using -Wnonnull - could this just be a spurious gcc > warning? Thanks, I should have caught that (I was even looking for that logic, but still missed it). That's what I get for writing patches while jet-lagged :-p -- Steve