From bc38e31b4e0366f3a70c0939abde4c3dd6e0fa30 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Fri, 23 Apr 2021 11:18:03 +0800 Subject: net: check the existence of peer before trying to pad There could be case that peer is NULL. This can happen when during network device hot-add where net device needs to be added first. So the patch check the existence of peer before trying to do the pad. Fixes: 969e50b61a285 ("net: Pad short frames to minimum size before sending from SLiRP/TAP") Signed-off-by: Jason Wang Reviewed-by: Bin Meng Reviewed-by: Stefan Weil Message-id: 20210423031803.1479-1-jasowang@redhat.com Signed-off-by: Peter Maydell --- net/slirp.c | 2 +- net/tap-win32.c | 2 +- net/tap.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/slirp.c b/net/slirp.c index a01a0fccd3..7a4e96db5c 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -119,7 +119,7 @@ static ssize_t net_slirp_send_packet(const void *pkt, size_t pkt_len, uint8_t min_pkt[ETH_ZLEN]; size_t min_pktsz = sizeof(min_pkt); - if (!s->nc.peer->do_not_pad) { + if (net_peer_needs_padding(&s->nc)) { if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pkt_len)) { pkt = min_pkt; pkt_len = min_pktsz; diff --git a/net/tap-win32.c b/net/tap-win32.c index 897bd18e32..6096972f5d 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -696,7 +696,7 @@ static void tap_win32_send(void *opaque) if (size > 0) { orig_buf = buf; - if (!s->nc.peer->do_not_pad) { + if (net_peer_needs_padding(&s->nc)) { if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) { buf = min_pkt; size = min_pktsz; diff --git a/net/tap.c b/net/tap.c index dd42ac6134..bae895e287 100644 --- a/net/tap.c +++ b/net/tap.c @@ -203,7 +203,7 @@ static void tap_send(void *opaque) size -= s->host_vnet_hdr_len; } - if (!s->nc.peer->do_not_pad) { + if (net_peer_needs_padding(&s->nc)) { if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) { buf = min_pkt; size = min_pktsz; -- cgit v1.2.3