Skip to content

Commit

Permalink
applespi: Verify crc before verifying fields.
Browse files Browse the repository at this point in the history
Minor, but we shouldn't really be looking at anything inside a message
before verifying the crc.
  • Loading branch information
roadrunner2 committed Mar 4, 2018
1 parent 3e04fc1 commit 917d8bc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions applespi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,15 +1385,15 @@ static void applespi_got_data(struct applespi_data *applespi)
applespi->saved_msg_len = 0;

/* got complete message - verify */
if (!applespi_verify_crc(applespi, (u8 *)message, msg_len))
goto cleanup;

if (le16_to_cpu(message->length) != msg_len - MSG_HEADER_SIZE - 2) {
dev_warn_ratelimited(&applespi->spi->dev,
"Received corrupted packet (invalid message length)\n");
goto cleanup;
}

if (!applespi_verify_crc(applespi, (u8 *)message, msg_len))
goto cleanup;

/* handle message */
if (packet->flags == PACKET_TYPE_READ &&
packet->device == PACKET_DEV_KEYB) {
Expand Down

0 comments on commit 917d8bc

Please sign in to comment.