Skip to contentSkip to conversation

commands: of_property: fix crashes on incorrect number of arguments

PATCH Applied Ahmad Fatoum 2 participants 2 messages Mar 30, 2020 – Mar 31, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commands: of_property: fix crashes on incorrect number of arguments

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.

---
 commands/of_property.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
commands/of_property.c +4 -7
index 31e9b71dd7d1..1d7ba181d5f0 100644
@@ -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);
 
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 10 lines · Ahmad Fatoum

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.

---
 commands/of_property.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Applied, thanks

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox