All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Atharva Tiwari <evepolonium@gmail.com>
Cc: atharvatiwari1101@outlook.in,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Naveen N Rao <naveen@kernel.org>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Ian Rogers <irogers@google.com>,
	Aditya Gupta <adityag@linux.ibm.com>,
	Jiri Olsa <jolsa@kernel.org>, Eder Zulian <ezulian@redhat.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fix: add safety check for OPTION_END and refactor code for consistency
Date: Wed, 4 Dec 2024 16:30:36 -0800	[thread overview]
Message-ID: <Z1D0LNfWcnPkWC3_@google.com> (raw)
In-Reply-To: <20241129104401.5997-1-atharvatiwari1101@outlook.in>

Hello,

On Fri, Nov 29, 2024 at 04:13:53PM +0530, Atharva Tiwari wrote:
> - Added a null check for 'o' before copying the last OPTION_END in options__order function to prevent potential uninitialized usage.
> - Refactored the parse_long_opt function for improved readability by aligning function signature.
> - Minor formatting fix to ensure consistency in the codebase.
> - Updated the wrapper script for pseries architecture to handle 'notext' option in a more reliable way.
> 
> Signed-off-by: Atharva Tiwari <atharvatiwari1101@outlook.in>
> ---
>  arch/powerpc/boot/wrapper        |  1 +
>  tools/lib/subcmd/parse-options.c | 10 +++++-----
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
> index 1db60fe13802..d25ad8c622f4 100755
> --- a/arch/powerpc/boot/wrapper
> +++ b/arch/powerpc/boot/wrapper
> @@ -267,6 +267,7 @@ pseries)
>      link_address='0x4000000'
>      if [ "$format" != "elf32ppc" ]; then
>  	link_address=
> +	notext='-z notext'

This is a completely differnt change and should be sent to powerpc devs
separately.


>  	pie=-pie
>      fi
>      make_space=n
> diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
> index 555d617c1f50..f85b642bc9aa 100644
> --- a/tools/lib/subcmd/parse-options.c
> +++ b/tools/lib/subcmd/parse-options.c
> @@ -360,8 +360,7 @@ static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *optio
>  	return -2;
>  }
>  
> -static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
> -                          const struct option *options)
> +static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, const struct option *options)

Please don't change this unnecessarily.


>  {
>  	const char *arg_end = strchr(arg, '=');
>  	const struct option *abbrev_option = NULL, *ambiguous_option = NULL;
> @@ -828,9 +827,10 @@ static struct option *options__order(const struct option *opts)
>  
>  		nr_parent = nr_opts;
>  	}
> -	/* copy the last OPTION_END */
> -	memcpy(&ordered[nr_opts], o, sizeof(*o));
> -
> +	/* Check whether o is  valid before using it to copy the last OPTION_END. */
> +	if (o && o->type == OPTION_END) {
> +		memcpy(&ordered[nr_opts], o, sizeof(*o));
> +	}

Do you any real problems with this?  I think the existing code assumes
the last entry should be OPTION_END.  Otherwise it won't work well.

Thanks,
Namhyung


>  	/* sort each option group individually */
>  	for (opt = group = ordered; opt->type != OPTION_END; opt++) {
>  		if (opt->type == OPTION_GROUP) {
> -- 
> 2.43.-1
> 


      reply	other threads:[~2024-12-05  0:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29 10:43 [PATCH] fix: add safety check for OPTION_END and refactor code for consistency Atharva Tiwari
2024-12-05  0:30 ` Namhyung Kim [this message]

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=Z1D0LNfWcnPkWC3_@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@redhat.com \
    --cc=adityag@linux.ibm.com \
    --cc=atharvatiwari1101@outlook.in \
    --cc=christophe.leroy@csgroup.eu \
    --cc=evepolonium@gmail.com \
    --cc=ezulian@redhat.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen@kernel.org \
    --cc=npiggin@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.