]> git.feebdaed.xyz Git - 0xmirror/SOEM.git/commitdiff
Add sanity check for mailbox size in ecx_EOEsend
authorHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Thu, 10 Jul 2025 07:48:21 +0000 (09:48 +0200)
committerHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Thu, 10 Jul 2025 09:59:09 +0000 (11:59 +0200)
Ensure that ecx_EOEsend is called with a valid slave to prevent memory
corruption. This check addresses potential issues when mistakenly
invoked on devices like the EK1100 EtherCAT coupler.

Change-Id: I82ceff6c3f22c69a1531e27a30586bd6f20afe44

src/ec_eoe.c

index 4a96729888894c9395651fdf1e7950fdfdbc1115..11e33a02dd140b914159df0c8677c86ae4af8a3f 100644 (file)
@@ -348,6 +348,14 @@ int ecx_EOEsend(ecx_contextt *context, uint16 slave, uint8 port, int psize, void
    txframeoffset = 0;
    NotLast = TRUE;
 
+   /* Sanity check size of slave mailbox */
+   if (maxdata < 0)
+   {
+      /* This slave does not have a suitable mailbox */
+      EC_PRINT("EoE: Bad mailbox size\n");
+      return -1;
+   }
+
    do
    {
       MbxOut = ecx_getmbx(context);