From 7ef28df980082d21069dfd878474ef9ea17db783 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 16 Aug 2017 17:48:11 +0300 Subject: [PATCH] Bluetooth: samples: ipsp: Fix crash on TCP connection closure Be sure to check for NULL pkt in receive callback, which means TCP EOF. The fix ported from echo_server sample. Jira: ZEP-2423 Signed-off-by: Paul Sokolovsky --- samples/bluetooth/ipsp/src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/samples/bluetooth/ipsp/src/main.c b/samples/bluetooth/ipsp/src/main.c index 4d20b656b43..0524819193e 100644 --- a/samples/bluetooth/ipsp/src/main.c +++ b/samples/bluetooth/ipsp/src/main.c @@ -270,10 +270,17 @@ static void tcp_received(struct net_context *context, void *user_data) { static char dbg[MAX_DBG_PRINT + 1]; - sa_family_t family = net_pkt_family(pkt); + sa_family_t family; struct net_pkt *reply_pkt; int ret; + if (!pkt) { + /* EOF condition */ + return; + } + + family = net_pkt_family(pkt); + snprintf(dbg, MAX_DBG_PRINT, "TCP IPv%c", family == AF_INET6 ? '6' : '4');