Change in libosmocore[master]: vty: Don't match negative values on purely positive ranges

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Thu Jul 30 21:02:05 UTC 2020


pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19424 )

Change subject: vty: Don't match negative values on purely positive ranges
......................................................................

vty: Don't match negative values on purely positive ranges

Without this patch, for instance having a range 0-ULONG_MAX would match
if someones types value -3, which would be converted to unsigned but
that's clearly what is expected here from user point of view.

Change-Id: Ia95f6314a2dd3f94d21fc219cf69bb8d39b8e7f0
---
M src/vty/command.c
M tests/vty/vty_test.c
M tests/vty/vty_test.ok
3 files changed, 5 insertions(+), 3 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  Hoernchen: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/vty/command.c b/src/vty/command.c
index 16dd07f..278ceb5 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -1325,6 +1325,9 @@
 	} else {
 		unsigned long min, max, val;
 
+		if (str[0] == '-')
+			return 0;
+
 		val = strtoul(str, &endptr, 10);
 		if (*endptr != '\0')
 			return 0;
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index a7aef11..b2d34ad 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -508,7 +508,7 @@
 
 	OSMO_ASSERT(do_vty_command(vty, "numeric-range 0") == CMD_SUCCESS);
 	OSMO_ASSERT(do_vty_command(vty, "numeric-range 40000") == CMD_SUCCESS);
-	OSMO_ASSERT(do_vty_command(vty, "numeric-range -400000") == CMD_SUCCESS);
+	OSMO_ASSERT(do_vty_command(vty, "numeric-range -400000") == CMD_ERR_NO_MATCH);
 
 	destroy_test_vty(&test, vty);
 }
diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok
index bac083d..5f509f6 100644
--- a/tests/vty/vty_test.ok
+++ b/tests/vty/vty_test.ok
@@ -319,6 +319,5 @@
 Called: 'return-success'
 Returned: 0, Current node: 1 '%s> '
 Going to execute 'numeric-range -400000'
-Called: 'return-success'
-Returned: 0, Current node: 1 '%s> '
+Returned: 2, Current node: 1 '%s> '
 All tests passed

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19424
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia95f6314a2dd3f94d21fc219cf69bb8d39b8e7f0
Gerrit-Change-Number: 19424
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200730/c7f9c4c5/attachment.htm>


More information about the gerrit-log mailing list