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.orgpespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19457 ) Change subject: vty: Allow 64 bit values in numeric ranges if system supports it ...................................................................... vty: Allow 64 bit values in numeric ranges if system supports it This fixes commands not being matched due to providing a range with more than 10 digits. The last case (passing -4000 matching 0-ULONG_MAX) shows a different bug which will be fixed in next commit. Change-Id: I0afa0caabffe36083c36b92ba90696ded00bb7be --- M src/vty/command.c M tests/vty/vty_test.c M tests/vty/vty_test.ok 3 files changed, 31 insertions(+), 12 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 9b32d22..16dd07f 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -37,6 +37,7 @@ #include <unistd.h> #include <ctype.h> #include <time.h> +#include <limits.h> #include <sys/time.h> #include <sys/stat.h> @@ -1262,12 +1263,27 @@ #endif /* HAVE_IPV6 */ -#define DECIMAL_STRLEN_MAX 10 + +#if ULONG_MAX == 18446744073709551615UL +#define DECIMAL_STRLEN_MAX_UNSIGNED 20 +#elif ULONG_MAX == 4294967295UL +#define DECIMAL_STRLEN_MAX_UNSIGNED 10 +#else +#error "ULONG_MAX not defined!" +#endif + +#if LONG_MAX == 9223372036854775807L +#define DECIMAL_STRLEN_MAX_SIGNED 19 +#elif LONG_MAX == 2147483647L +#define DECIMAL_STRLEN_MAX_SIGNED 10 +#else +#error "LONG_MAX not defined!" +#endif static int cmd_range_match(const char *range, const char *str) { char *p; - char buf[DECIMAL_STRLEN_MAX + 1]; + char buf[DECIMAL_STRLEN_MAX_UNSIGNED + 1]; char *endptr = NULL; if (str == NULL) @@ -1284,7 +1300,7 @@ p = strchr(range, '-'); if (p == NULL) return 0; - if (p - range > DECIMAL_STRLEN_MAX) + if (p - range > DECIMAL_STRLEN_MAX_SIGNED) return 0; strncpy(buf, range, p - range); buf[p - range] = '\0'; @@ -1296,7 +1312,7 @@ p = strchr(range, '>'); if (p == NULL) return 0; - if (p - range > DECIMAL_STRLEN_MAX) + if (p - range > DECIMAL_STRLEN_MAX_SIGNED) return 0; strncpy(buf, range, p - range); buf[p - range] = '\0'; @@ -1317,7 +1333,7 @@ p = strchr(range, '-'); if (p == NULL) return 0; - if (p - range > DECIMAL_STRLEN_MAX) + if (p - range > DECIMAL_STRLEN_MAX_UNSIGNED) return 0; strncpy(buf, range, p - range); buf[p - range] = '\0'; @@ -1329,7 +1345,7 @@ p = strchr(range, '>'); if (p == NULL) return 0; - if (p - range > DECIMAL_STRLEN_MAX) + if (p - range > DECIMAL_STRLEN_MAX_UNSIGNED) return 0; strncpy(buf, range, p - range); buf[p - range] = '\0'; diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c index 7146a1d..a7aef11 100644 --- a/tests/vty/vty_test.c +++ b/tests/vty/vty_test.c @@ -506,9 +506,9 @@ printf("Going to test test_numeric_range()\n"); vty = create_test_vty(&test); - OSMO_ASSERT(do_vty_command(vty, "numeric-range 0") == CMD_ERR_NO_MATCH); - OSMO_ASSERT(do_vty_command(vty, "numeric-range 40000") == CMD_ERR_NO_MATCH); - OSMO_ASSERT(do_vty_command(vty, "numeric-range -400000") == CMD_ERR_NO_MATCH); + 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); destroy_test_vty(&test, vty); } diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok index d81c6c7..bac083d 100644 --- a/tests/vty/vty_test.ok +++ b/tests/vty/vty_test.ok @@ -313,9 +313,12 @@ Returned: 0, Current node: 1 '%s> ' Going to test test_numeric_range() Going to execute 'numeric-range 0' -Returned: 2, Current node: 1 '%s> ' +Called: 'return-success' +Returned: 0, Current node: 1 '%s> ' Going to execute 'numeric-range 40000' -Returned: 2, Current node: 1 '%s> ' +Called: 'return-success' +Returned: 0, Current node: 1 '%s> ' Going to execute 'numeric-range -400000' -Returned: 2, Current node: 1 '%s> ' +Called: 'return-success' +Returned: 0, Current node: 1 '%s> ' All tests passed -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19457 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I0afa0caabffe36083c36b92ba90696ded00bb7be Gerrit-Change-Number: 19457 Gerrit-PatchSet: 2 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/123b1499/attachment.htm>