Skip to content

Commit 954c707

Browse files
Dave Barachflorincoras
authored andcommitted
misc: check return values from vlib_buffer_copy(...)
vlib_buffer_copy(...) returns NULL if the system is temporarily out of buffers. This is NOT correct. Please don't be this person: c0 = vlib_buffer_copy (vm, p0); ci0 = vlib_get_buffer_index (vm, c0); Type: fix Signed-off-by: Dave Barach <[email protected]> Change-Id: Ic25ef58965871ea5d2b40904df9506803f69e47e
1 parent 8d0d8d2 commit 954c707

File tree

8 files changed

+30
-4
lines changed

8 files changed

+30
-4
lines changed

src/plugins/dhcp/dhcp4_proxy_error.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ dhcp_proxy_error (BAD_YIADDR, "DHCP packets with bad your_ip_address fields")
3030
dhcp_proxy_error (BAD_SVR_FIB_OR_ADDRESS, "DHCP packets not from DHCP server or server FIB.")
3131
dhcp_proxy_error (PKT_TOO_BIG, "DHCP packets which are too big.")
3232
dhcp_proxy_error (FOR_US, "DHCP packets for local client.")
33-
33+
dhcp_proxy_error (ALLOC_FAIL, "DHCP buffer allocation failures.")

src/plugins/dhcp/dhcp4_proxy_node.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ dhcp_proxy_to_server_input (vlib_main_t * vm,
364364
u32 ci0;
365365

366366
c0 = vlib_buffer_copy (vm, b0);
367+
if (c0 == NULL)
368+
{
369+
vlib_node_increment_counter
370+
(vm, dhcp_proxy_to_server_node.index,
371+
DHCP_PROXY_ERROR_ALLOC_FAIL, 1);
372+
continue;
373+
}
367374
VLIB_BUFFER_TRACE_TRAJECTORY_INIT (c0);
368375
ci0 = vlib_get_buffer_index (vm, c0);
369376
server = &proxy->dhcp_servers[ii];

src/plugins/dhcp/dhcp6_ia_na_client_dp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ check_send_client_message (vlib_main_t * vm,
258258
next_index = ip6_rewrite_mcast_node.index;
259259

260260
c0 = vlib_buffer_copy (vm, p0);
261+
if (c0 == NULL)
262+
return client_state->keep_sending_client_message;
263+
261264
ci0 = vlib_get_buffer_index (vm, c0);
262265

263266
ip = (ip6_header_t *) vlib_buffer_get_current (c0);

src/plugins/dhcp/dhcp6_pd_client_dp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ check_pd_send_client_message (vlib_main_t * vm,
264264
next_index = ip6_rewrite_mcast_node.index;
265265

266266
c0 = vlib_buffer_copy (vm, p0);
267+
if (c0 == NULL)
268+
return client_state->keep_sending_client_message;
269+
267270
ci0 = vlib_get_buffer_index (vm, c0);
268271

269272
ip = (ip6_header_t *) vlib_buffer_get_current (c0);

src/plugins/dhcp/dhcp6_proxy_error.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ dhcpv6_proxy_error (NO_RELAY_MESSAGE_OPTION, "DHCPv6 reply packets without relay
2727
dhcpv6_proxy_error (BAD_SVR_FIB_OR_ADDRESS, "DHCPv6 packets not from DHCPv6 server or server FIB.")
2828
dhcpv6_proxy_error (PKT_TOO_BIG, "DHCPv6 packets which are too big.")
2929
dhcpv6_proxy_error (WRONG_INTERFACE_ID_OPTION, "DHCPv6 reply to invalid interface.")
30+
dhcpv6_proxy_error (ALLOC_FAIL, "DHCPv6 buffer allocation failures.")

src/plugins/dhcp/dhcp6_proxy_node.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ dhcpv6_proxy_to_server_input (vlib_main_t * vm,
437437
u32 ci0;
438438

439439
c0 = vlib_buffer_copy (vm, b0);
440+
if (c0 == NULL)
441+
{
442+
vlib_node_increment_counter
443+
(vm, dhcpv6_proxy_to_server_node.index,
444+
DHCPV6_PROXY_ERROR_ALLOC_FAIL, 1);
445+
continue;
446+
}
440447
VLIB_BUFFER_TRACE_TRAJECTORY_INIT (c0);
441448
ci0 = vlib_get_buffer_index (vm, c0);
442449
server = &proxy->dhcp_servers[ii];

src/plugins/ioam/encap/ip6_ioam_trace.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,16 @@ ip6_hbh_ioam_loopback_handler (vlib_buffer_t * b, ip6_header_t * ip,
222222
ioam_trace_option_t *opt;
223223
udp_ping_t *udp;
224224

225+
b0 = vlib_buffer_copy (hm->vlib_main, b);
226+
if (b0 == NULL)
227+
return;
228+
229+
buf_index = vlib_get_buffer_index (hm->vlib_main, b0);
225230
next_node = vlib_get_node_by_name (hm->vlib_main, (u8 *) "ip6-lookup");
226231
nf = vlib_get_frame_to_node (hm->vlib_main, next_node->index);
227232
nf->n_vectors = 0;
228233
to_next = vlib_frame_vector_args (nf);
229234

230-
b0 = vlib_buffer_copy (hm->vlib_main, b);
231-
buf_index = vlib_get_buffer_index (hm->vlib_main, b0);
232-
233235
vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
234236
vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
235237

src/vnet/ip6-nd/ip6_ra.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,9 @@ check_send_rs (vlib_main_t * vm, ip6_ra_t * radv_info, f64 current_time,
12191219
next_index = ip6_rewrite_mcast_node.index;
12201220

12211221
c0 = vlib_buffer_copy (vm, p0);
1222+
if (c0 == NULL)
1223+
return radv_info->keep_sending_rs;
1224+
12221225
ci0 = vlib_get_buffer_index (vm, c0);
12231226

12241227
f = vlib_get_frame_to_node (vm, next_index);

0 commit comments

Comments
 (0)