mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: of_property: fix crashes on incorrect number of arguments
@ 2020-03-30 14:33 Ahmad Fatoum
  2020-03-31  5:18 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2020-03-30 14:33 UTC (permalink / raw)
  To: barebox

of_property needs at least two parameters, the path and the property
name. If we supply less, we risk crashes, e.g. by running
of_property -fs /test

Verify we got at least two parameters.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 commands/of_property.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/commands/of_property.c b/commands/of_property.c
index 31e9b71dd7d1..1d7ba181d5f0 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -315,7 +315,7 @@ static int do_of_property(int argc, char *argv[])
 	int delete = 0;
 	int set = 0;
 	int fixup = 0;
-	char *path = NULL, *propname = NULL;
+	char *path, *propname;
 
 	while ((opt = getopt(argc, argv, "dsf")) > 0) {
 		switch (opt) {
@@ -333,14 +333,11 @@ static int do_of_property(int argc, char *argv[])
 		}
 	}
 
-	if (optind == argc)
+	if (argc - optind < 2)
 		return COMMAND_ERROR_USAGE;
 
-	if (optind < argc)
-		path = argv[optind];
-
-	if (optind + 1 < argc)
-		propname = argv[optind + 1];
+	path = argv[optind];
+	propname = argv[optind + 1];
 
 	debug("path: %s propname: %s\n", path, propname);
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] commands: of_property: fix crashes on incorrect number of arguments
  2020-03-30 14:33 [PATCH] commands: of_property: fix crashes on incorrect number of arguments Ahmad Fatoum
@ 2020-03-31  5:18 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-03-31  5:18 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Mar 30, 2020 at 04:33:55PM +0200, Ahmad Fatoum wrote:
> of_property needs at least two parameters, the path and the property
> name. If we supply less, we risk crashes, e.g. by running
> of_property -fs /test
> 
> Verify we got at least two parameters.
> 
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
>  commands/of_property.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-03-31  5:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 14:33 [PATCH] commands: of_property: fix crashes on incorrect number of arguments Ahmad Fatoum
2020-03-31  5:18 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox