diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2020-03-30 16:33:55 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-31 07:17:25 +0200 |
commit | 02e1547fc1c6dc8f7f1bffc2f1c323bc0866eb2a (patch) | |
tree | 1b9427154ce275e15a9193b733b431c0d7919990 /commands | |
parent | 819388392785c4f49e4cbd9bf09eb531ce852739 (diff) | |
download | barebox-02e1547fc1c6dc8f7f1bffc2f1c323bc0866eb2a.tar.gz barebox-02e1547fc1c6dc8f7f1bffc2f1c323bc0866eb2a.tar.xz |
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.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/of_property.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/commands/of_property.c b/commands/of_property.c index 31e9b71dd7..1d7ba181d5 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); |