Skip to content

Commit f8ac2f2

Browse files
committed
fix(isotp): move size validation to the begining of isotp_user_send_can
1 parent aecd033 commit f8ac2f2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

esp_isotp/src/esp_isotp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ int isotp_user_send_can(const uint32_t arbitration_id, const uint8_t *data, cons
208208
esp_isotp_handle_t isotp_handle = (esp_isotp_handle_t) user_data;
209209
ESP_RETURN_ON_FALSE_ISR(isotp_handle != NULL, ISOTP_RET_ERROR, TAG, "Invalid ISO-TP handle");
210210

211+
// Size validation - TWAI frames are max 8 bytes by protocol
212+
ESP_RETURN_ON_FALSE_ISR(size <= 8, ISOTP_RET_ERROR, TAG, "Invalid TWAI frame size");
213+
211214
twai_node_handle_t twai_node = isotp_handle->twai_node;
212215

213216
// Get a pre-allocated frame from the SLIST pool.
@@ -223,9 +226,6 @@ int isotp_user_send_can(const uint32_t arbitration_id, const uint8_t *data, cons
223226
tx_frame->frame.header.id = arbitration_id;
224227
tx_frame->frame.header.ide = is_extended_id(arbitration_id); // Extended (29-bit) vs Standard (11-bit) ID
225228

226-
// Size validation - TWAI frames are max 8 bytes by protocol
227-
ESP_RETURN_ON_FALSE_ISR(size <= 8, ISOTP_RET_ERROR, TAG, "Invalid TWAI frame size");
228-
229229
// Copy payload into the embedded buffer to ensure data lifetime during async transmission.
230230
memcpy(tx_frame->data_payload, data, size);
231231

0 commit comments

Comments
 (0)