rdma: fix non-NULL terminated C-string overflow
[vpp.git] / src / plugins / rdma / format.c
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
22
23 #include <rdma/rdma.h>
24
25 u8 *
26 format_rdma_device_name (u8 * s, va_list * args)
27 {
28   u32 i = va_arg (*args, u32);
29   rdma_main_t *rm = &rdma_main;
30   rdma_device_t *rd = vec_elt_at_index (rm->devices, i);
31
32   if (rd->name)
33     return format (s, "%v", rd->name);
34
35   s = format (s, "rdma-%u", rd->dev_instance);
36   return s;
37 }
38
39 u8 *
40 format_rdma_device_flags (u8 * s, va_list * args)
41 {
42   rdma_device_t *rd = va_arg (*args, rdma_device_t *);
43   u8 *t = 0;
44
45 #define _(a, b, c) if (rd->flags & (1 << a)) \
46 t = format (t, "%s%s", t ? " ":"", c);
47   foreach_rdma_device_flags
48 #undef _
49     s = format (s, "%v", t);
50   vec_free (t);
51   return s;
52 }
53
54 u8 *
55 format_rdma_device (u8 * s, va_list * args)
56 {
57   u32 i = va_arg (*args, u32);
58   rdma_main_t *rm = &rdma_main;
59   rdma_device_t *rd = vec_elt_at_index (rm->devices, i);
60   u32 indent = format_get_indent (s);
61
62   s = format (s, "netdev: %v\n", rd->linux_ifname);
63   s = format (s, "%Uflags: %U", format_white_space, indent,
64               format_rdma_device_flags, rd);
65   if (rd->error)
66     s = format (s, "\n%Uerror %U", format_white_space, indent,
67                 format_clib_error, rd->error);
68
69   return s;
70 }
71
72 u8 *
73 format_rdma_input_trace (u8 * s, va_list * args)
74 {
75   vlib_main_t *vm = va_arg (*args, vlib_main_t *);
76   vlib_node_t *node = va_arg (*args, vlib_node_t *);
77   rdma_input_trace_t *t = va_arg (*args, rdma_input_trace_t *);
78   vnet_main_t *vnm = vnet_get_main ();
79   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, t->hw_if_index);
80
81   s = format (s, "rdma: %v (%d) next-node %U",
82               hi->name, t->hw_if_index, format_vlib_next_node_name, vm,
83               node->index, t->next_index);
84
85   return s;
86 }
87
88 /*
89  * fd.io coding-style-patch-verification: ON
90  *
91  * Local Variables:
92  * eval: (c-set-style "gnu")
93  * End:
94  */