summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@samsung.com>2018-08-14 10:53:15 +0300
committerBen Pfaff <blp@ovn.org>2018-08-15 11:36:18 -0700
commitcbcf40a847c0539fec36e82410f0966f13517964 (patch)
tree0970a16b5b1ba1e7c34826c6e74197f4dd59cfcb /tests
parentb302f315b38b9bf35036ef8d0542bf83bb0e0752 (diff)
downloadopenvswitch-cbcf40a847c0539fec36e82410f0966f13517964.tar.gz
utilities: Fix and unify parsing of timeout option.
Parsing of the '--timeout' option implemented differently for every single control utility and, which is more important, highly inaccurate. In most cases unsigned result of 'strtoul' stored in signed variable. Parsing failures are not tracked. 'ovs-appctl' even uses just 'atoi' without any checking of the argument or result. This patch unifies the parsing by using 'str_to_uint'. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-ovsdb.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
index 793220400..4b216fe74 100644
--- a/tests/test-ovsdb.c
+++ b/tests/test-ovsdb.c
@@ -96,7 +96,7 @@ parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
- unsigned long int timeout;
+ unsigned int timeout = 0;
int c;
c = getopt_long(argc, argv, short_options, long_options, NULL);
@@ -106,10 +106,8 @@ parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)
switch (c) {
case 't':
- timeout = strtoul(optarg, NULL, 10);
- if (timeout <= 0) {
- ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
- optarg);
+ if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
+ ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
} else {
time_alarm(timeout);
}