Check phy_request length for read operations, too!
authorFlorian Pose <fp@igh-essen.com>
Wed, 08 Apr 2009 11:48:00 +0000
changeset 1386 95ec1e9bcb53
parent 1385 241a7511eee9
child 1387 57020c731092
Check phy_request length for read operations, too!
master/fsm_master.c
--- a/master/fsm_master.c	Wed Apr 08 10:27:48 2009 +0000
+++ b/master/fsm_master.c	Wed Apr 08 11:48:00 2009 +0000
@@ -353,6 +353,16 @@
                     "offset 0x%04x, length %u...\n",
                     request->slave->ring_position,
                     request->offset, request->length);
+
+        if (request->length > fsm->datagram->mem_size) {
+            EC_ERR("Request length (%u) exceeds maximum "
+                    "datagram size (%u)!\n", request->length,
+                    fsm->datagram->mem_size);
+            request->state = EC_INT_REQUEST_FAILURE;
+            wake_up(&master->phy_queue);
+            continue;
+        }
+
         fsm->phy_request = request;
 
         if (request->dir == EC_DIR_INPUT) {
@@ -360,14 +370,6 @@
                     request->offset, request->length);
             ec_datagram_zero(fsm->datagram);
         } else {
-            if (request->length > fsm->datagram->mem_size) {
-                EC_ERR("Request length (%u) exceeds maximum "
-                        "datagram size (%u)!\n", request->length,
-                        fsm->datagram->mem_size);
-                request->state = EC_INT_REQUEST_FAILURE;
-                wake_up(&master->phy_queue);
-                continue;
-            }
             ec_datagram_fpwr(fsm->datagram, request->slave->station_address,
                     request->offset, request->length);
             memcpy(fsm->datagram->data, request->data, request->length);