From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [PATCH] commands: of_property: fix crashes on incorrect number of arguments
Date: Mon, 30 Mar 2020 16:33:55 +0200 [thread overview]
Message-ID: <20200330143355.652318-1-ahmad@a3f.at> (raw)
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
next reply other threads:[~2020-03-30 14:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 14:33 Ahmad Fatoum [this message]
2020-03-31 5:18 ` Sascha Hauer
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=20200330143355.652318-1-ahmad@a3f.at \
--to=ahmad@a3f.at \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox