From 0b924c79ceb7b3c46d82dd00f6f1ed3f664d02d0 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 28 Jun 2024 22:28:14 -0400 Subject: [PATCH] add some safety checks to enet_packet_resize --- packet.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packet.c b/packet.c index d51c6404..832cff96 100644 --- a/packet.c +++ b/packet.c @@ -89,9 +89,14 @@ enet_packet_resize (ENetPacket * packet, size_t dataLength) if (newData == NULL) return -1; - memcpy (newData, packet -> data, packet -> dataLength); - enet_free (packet -> data); - + if (packet -> data != NULL) + { + if (packet -> dataLength > 0) + memcpy (newData, packet -> data, packet -> dataLength); + + enet_free (packet -> data); + } + packet -> data = newData; packet -> dataLength = dataLength;