From fb18f9fc6ebd09d9bb2692f1b4f26d093d0b97bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= Date: Mon, 23 Nov 2020 15:47:44 +0200 Subject: [PATCH] iphlpapi: Make sure there's no gap between the ICMP_ECHO_REPLY array and the data. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Ivăncescu Signed-off-by: Alexandre Julliard --- dlls/iphlpapi/icmp.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dlls/iphlpapi/icmp.c b/dlls/iphlpapi/icmp.c index 79fd35f524c..d59bb4ba77f 100644 --- a/dlls/iphlpapi/icmp.c +++ b/dlls/iphlpapi/icmp.c @@ -309,6 +309,25 @@ static DWORD icmp_get_reply(int sid, unsigned char *buffer, DWORD send_time, voi if (res==0) SetLastError(IP_REQ_TIMED_OUT); done: + if (res) + { + /* Move the data so there's no gap between it and the ICMP_ECHO_REPLY array */ + DWORD gap_size = endbuf - (char*)ier; + + if (gap_size) + { + memmove(ier, endbuf, ((char*)reply_buf + reply_size) - endbuf); + + /* Fix the pointers */ + while (ier-- != reply_buf) + { + ier->Data = (char*)ier->Data - gap_size; + if (ier->Options.OptionsData) + ier->Options.OptionsData -= gap_size; + } + } + } + HeapFree(GetProcessHeap(), 0, buffer); TRACE("received %d replies\n",res); return res;