diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-12 00:00:00 +0000 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-15 23:43:53 +0100 |
commit | d9748d753f34a030ee483e7723037ec4d335fae3 (patch) | |
tree | a317e2a0a7350285118bbee04e13e4a1108bc797 /bin | |
parent | 7a033fa8b762c2a247e32317ffd436dd6403c942 (diff) | |
download | dconf-d9748d753f34a030ee483e7723037ec4d335fae3.tar.gz |
bin: Consistently validate the number of arguments
Diffstat (limited to 'bin')
-rw-r--r-- | bin/dconf-dump.vala | 8 | ||||
-rw-r--r-- | bin/dconf.vala | 38 |
2 files changed, 46 insertions, 0 deletions
diff --git a/bin/dconf-dump.vala b/bin/dconf-dump.vala index d63e3eb..26f62d0 100644 --- a/bin/dconf-dump.vala +++ b/bin/dconf-dump.vala @@ -39,6 +39,10 @@ void dconf_dump (string[] args) throws Error { DConf.verify_dir (dir); + if (args[3] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + add_to_keyfile (kf, client, dir); print ("%s", kf.to_data ()); } @@ -62,6 +66,10 @@ void dconf_load (string[] args) throws Error { var dir = args[2]; DConf.verify_dir (dir); + if (args[3] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + var changeset = new DConf.Changeset (); var kf = keyfile_from_stdin (); diff --git a/bin/dconf.vala b/bin/dconf.vala index 8b0f211..1f0109c 100644 --- a/bin/dconf.vala +++ b/bin/dconf.vala @@ -173,6 +173,10 @@ void dconf_read (string?[] args) throws Error { DConf.verify_key (key); + if (args[index + 1] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + var result = client.read_full (key, flags, null); if (result != null) { @@ -200,6 +204,10 @@ void dconf_list_locks (string?[] args) throws Error { DConf.verify_dir (dir); + if (args[3] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + foreach (var item in client.list_locks (dir)) { print ("%s\n", item); } @@ -208,10 +216,21 @@ void dconf_list_locks (string?[] args) throws Error { void dconf_write (string?[] args) throws Error { var client = new DConf.Client (); var key = args[2]; + if (key == null) { + throw new OptionError.FAILED ("key not specified"); + } + var val = args[3]; + if (val == null) { + throw new OptionError.FAILED ("value not specified"); + } DConf.verify_key (key); + if (args[4] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + client.write_sync (key, Variant.parse (null, val)); } @@ -229,6 +248,10 @@ void dconf_reset (string?[] args) throws Error { DConf.verify_path (path); + if (args[index + 1] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + if (DConf.is_dir (path) && !force) { throw new OptionError.FAILED ("-f must be given to (recursively) reset entire dirs"); } @@ -259,6 +282,10 @@ void dconf_watch (string?[] args) throws Error { DConf.verify_path (path); + if (args[3] != null) { + throw new OptionError.FAILED ("too many arguments"); + } + client.changed.connect (watch_function); client.watch_sync (path); @@ -274,7 +301,18 @@ void dconf_blame (string?[] args) throws Error { void dconf_complete (string[] args) throws Error { var suffix = args[2]; + if (suffix == null) { + throw new OptionError.FAILED ("suffix not specified"); + } + var path = args[3]; + if (path == null) { + throw new OptionError.FAILED ("path not specified"); + } + + if (args[4] != null) { + throw new OptionError.FAILED ("too many arguments"); + } if (path == "") { print ("/\n"); |