linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix: add safety check for OPTION_END and refactor code for consistency
@ 2024-11-29 10:43 Atharva Tiwari
  2024-12-05  0:30 ` Namhyung Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Atharva Tiwari @ 2024-11-29 10:43 UTC (permalink / raw)
  Cc: atharvatiwari1101, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, Naveen N Rao, Madhavan Srinivasan,
	Arnaldo Carvalho de Melo, Ian Rogers, Namhyung Kim, Aditya Gupta,
	Jiri Olsa, Eder Zulian, linuxppc-dev, linux-kernel

- 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'
 	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)
 {
 	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));
+	}
 	/* sort each option group individually */
 	for (opt = group = ordered; opt->type != OPTION_END; opt++) {
 		if (opt->type == OPTION_GROUP) {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-05  0:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).