From 13bd75331861e52d997aaa9f2ea454e0ef4141b5 Mon Sep 17 00:00:00 2001
From: Owen Smith <owen.smith@cloud.com>
Date: Thu, 3 Apr 2025 13:53:33 +0100
Subject: Dont reference In buffer after writing to Out buffer

In and Out both refer to the same I/O buffer, so referencing the In structure
after updating the value in the Out structure cal lead to the wrong results,
if the fields overlap.

Also reformats the function arguments and variable definitions.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
Reviewed-by: Tu Dinh <ngoc-tu.dinh@vates.tech>
Reviewed-by: Paul Durrant <paul@xen.org>
---
 src/xeniface/ioctl_evtchn.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/xeniface/ioctl_evtchn.c b/src/xeniface/ioctl_evtchn.c
index f5284858076e..6d6399650e54 100644
--- a/src/xeniface/ioctl_evtchn.c
+++ b/src/xeniface/ioctl_evtchn.c
@@ -210,9 +210,6 @@ IoctlEvtchnBindUnbound(
 
     ExInterlockedInsertTailList(&Fdo->EvtchnList, &Context->Entry, &Fdo->EvtchnLock);
 
-    Out->LocalPort = Context->LocalPort;
-    *Info = sizeof(XENIFACE_EVTCHN_BIND_UNBOUND_OUT);
-
     if (!In->Mask) {
         (VOID) XENBUS_EVTCHN(Unmask,
                              &Fdo->EvtchnInterface,
@@ -221,6 +218,9 @@ IoctlEvtchnBindUnbound(
                              TRUE);
     }
 
+    Out->LocalPort = Context->LocalPort;
+    *Info = sizeof(XENIFACE_EVTCHN_BIND_UNBOUND_OUT);
+
     Trace("< LocalPort %lu, Context %p\n", Context->LocalPort, Context);
     return STATUS_SUCCESS;
 
@@ -304,9 +304,6 @@ IoctlEvtchnBindInterdomain(
 
     ExInterlockedInsertTailList(&Fdo->EvtchnList, &Context->Entry, &Fdo->EvtchnLock);
 
-    Out->LocalPort = Context->LocalPort;
-    *Info = sizeof(XENIFACE_EVTCHN_BIND_INTERDOMAIN_OUT);
-
     if (!In->Mask) {
         (VOID) XENBUS_EVTCHN(Unmask,
                              &Fdo->EvtchnInterface,
@@ -315,6 +312,9 @@ IoctlEvtchnBindInterdomain(
                              TRUE);
     }
 
+    Out->LocalPort = Context->LocalPort;
+    *Info = sizeof(XENIFACE_EVTCHN_BIND_INTERDOMAIN_OUT);
+
     Trace("< LocalPort %lu, Context %p\n", Context->LocalPort, Context);
 
     return STATUS_SUCCESS;
-- 
2.47.1

