[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/8] log: Avoid buffer overrun in DbgPrint interception



Truncate incomming strings to fit inside a Slot's Buffer

Assisted-by: ClaudeCode:claude-opus-4.8
Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/xen/log.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/xen/log.c b/src/xen/log.c
index 8673105..93039f6 100644
--- a/src/xen/log.c
+++ b/src/xen/log.c
@@ -545,6 +545,7 @@ LogDebugPrint(
 {
     PLOG_CONTEXT        Context = &LogContext;
     KIRQL               Irql;
+    ULONG               Length;
     PLOG_SLOT           Slot;
 
     UNREFERENCED_PARAMETER(ComponentId);
@@ -571,9 +572,14 @@ LogDebugPrint(
 
     Slot = &Context->Slot[Context->Pending++];
 
+    // truncate long log lines - avoid buffer overrun on Slot->Buffer
+    Length = Ansi->Length >= LOG_BUFFER_SIZE ?
+                            LOG_BUFFER_SIZE - 1:
+                            Ansi->Length;
+
     Slot->Level = 1 << Level;
-    RtlCopyMemory(Slot->Buffer, Ansi->Buffer, Ansi->Length);
-    Slot->Offset = Ansi->Length;
+    RtlCopyMemory(Slot->Buffer, Ansi->Buffer, Length);
+    Slot->Offset = Length;
 
     ReleaseHighLock(&Context->Lock, Irql);
 
-- 
2.51.2.windows.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.