aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty/command.c
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-07-30 14:56:38 +0200
committerpespin <pespin@sysmocom.de>2020-07-30 21:02:03 +0000
commit9fdc8715323a5ed621050c5541b9d7bd254c93c1 (patch)
treef309ce9f21f3ff6c71c87cd9c5fc24ab443f9501 /src/vty/command.c
parentd92be9ad13322268ec46073f4d271c4b34687dd7 (diff)
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
Diffstat (limited to 'src/vty/command.c')
-rw-r--r--src/vty/command.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/vty/command.c b/src/vty/command.c
index 9b32d22d..16dd07fa 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -37,6 +37,7 @@ Boston, MA 02110-1301, USA. */
#include <unistd.h>
#include <ctype.h>
#include <time.h>
+#include <limits.h>
#include <sys/time.h>
#include <sys/stat.h>
@@ -1262,12 +1263,27 @@ static enum match_type cmd_ipv6_prefix_match(const char *str)
#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 @@ static int cmd_range_match(const char *range, const char *str)
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 @@ static int cmd_range_match(const char *range, const char *str)
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 @@ static int cmd_range_match(const char *range, const char *str)
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 @@ static int cmd_range_match(const char *range, const char *str)
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';