From 61bbb753e3899f705aafd2538f0ab09ebdd5ae8c Mon Sep 17 00:00:00 2001 From: zouyonghao Date: Wed, 21 Oct 2020 20:58:40 +0800 Subject: [PATCH] Fix NULL pointer if we read before receiving any packet with data --- mtcp/src/api.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mtcp/src/api.c b/mtcp/src/api.c index c53714bcf..9165143db 100644 --- a/mtcp/src/api.c +++ b/mtcp/src/api.c @@ -1124,6 +1124,11 @@ CopyToUser(mtcp_manager_t mtcp, tcp_stream *cur_stream, char *buf, int len) uint32_t prev_rcv_wnd; int copylen; + if (rcvvar->rcvbuf == NULL) { + errno = EAGAIN; + return -1; + } + copylen = MIN(rcvvar->rcvbuf->merged_len, len); if (copylen <= 0) { errno = EAGAIN;