From ffe271b0c61100f858921e0cc71924591c5b7e52 Mon Sep 17 00:00:00 2001
From: jgromes <jan.gromes@gmail.com>
Date: Mon, 29 Nov 2021 08:05:46 +0100
Subject: [PATCH] [PHY] Fix unknown string length buffer overrun (#413)

---
 src/protocols/PhysicalLayer/PhysicalLayer.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp
index 58bb9231..8b514a9c 100644
--- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp
+++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp
@@ -107,7 +107,12 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
   #if defined(RADIOLIB_STATIC_ONLY)
     uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
   #else
-    uint8_t* data = new uint8_t[length + 1];
+    uint8_t* data = NULL;
+    if(length == 0) {
+      data = new uint8_t[_maxPacketLength + 1];
+    } else {
+      data = new uint8_t[length + 1];
+    }
     if(!data) {
       return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
     }