aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElias Rudberg <elias.rudberg@bahnhof.net>2020-05-27 01:03:46 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-08-18 19:47:21 +0000
commita4a794d152d31d2c81528951052c3068d68108f5 (patch)
tree6c2a538509e58a0f0e8887601070ed1811819ce5
parent895c37fb8ab0d97fafa792bd399baa07f8fac98d (diff)
misc: ipfix-export unformat u16 collector_port fix
Use %U and unformat_udp_port instead of %u for unformat() call for u16 collector_port number in set_ipfix_exporter_command_fn() to avoid corruption of other variables which can happen if unformat() with %u is used with a 16-bit variable. This avoids crash due to corrupted fib_index value. Type: fix Signed-off-by: Elias Rudberg <elias.rudberg@bahnhof.net> Change-Id: Id54273fcc458a7f9c5aa4025aa91711f160c1c1a (cherry picked from commit 2dca180db989ea7afacdf4e70cc85e4408557382)
-rw-r--r--src/vnet/ipfix-export/flow_report.c3
-rw-r--r--src/vnet/udp/udp.h1
-rw-r--r--src/vnet/udp/udp_format.c17
3 files changed, 20 insertions, 1 deletions
diff --git a/src/vnet/ipfix-export/flow_report.c b/src/vnet/ipfix-export/flow_report.c
index 1976ffc0796..56a2d16b8d5 100644
--- a/src/vnet/ipfix-export/flow_report.c
+++ b/src/vnet/ipfix-export/flow_report.c
@@ -500,7 +500,8 @@ set_ipfix_exporter_command_fn (vlib_main_t * vm,
{
if (unformat (input, "collector %U", unformat_ip4_address, &collector))
;
- else if (unformat (input, "port %u", &collector_port))
+ else if (unformat (input, "port %U", unformat_udp_port,
+ &collector_port))
;
else if (unformat (input, "src %U", unformat_ip4_address, &src))
;
diff --git a/src/vnet/udp/udp.h b/src/vnet/udp/udp.h
index 5ff613b568a..a5c7b53394e 100644
--- a/src/vnet/udp/udp.h
+++ b/src/vnet/udp/udp.h
@@ -256,6 +256,7 @@ udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4)
format_function_t format_udp_header;
format_function_t format_udp_rx_trace;
unformat_function_t unformat_udp_header;
+unformat_function_t unformat_udp_port;
void udp_register_dst_port (vlib_main_t * vm,
udp_dst_port_t dst_port,
diff --git a/src/vnet/udp/udp_format.c b/src/vnet/udp/udp_format.c
index 2277e18bcdb..93e7508711b 100644
--- a/src/vnet/udp/udp_format.c
+++ b/src/vnet/udp/udp_format.c
@@ -82,6 +82,23 @@ format_udp_header (u8 * s, va_list * args)
return s;
}
+uword
+unformat_udp_port (unformat_input_t * input, va_list * args)
+{
+ u16 *result = va_arg (*args, u16 *);
+ int port;
+
+ /* Numeric type. */
+ if (unformat (input, "0x%x", &port) || unformat (input, "%d", &port))
+ {
+ if (port <= 0 || port >= (1 << 16))
+ return 0;
+ *result = port;
+ return 1;
+ }
+ return 0;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*