dot11decrypt: Avoid unecessary memmove

When decrypting a frame the decryption occurs in a temporary buffer.
After successful decryption the decrypted frame is first copied back,
then a memmove operation is used to remove the CCMP header mid frame.

As the mac header is not encrypted there's no need to copy that part
back again after decryption. This means there's no mid frame data
that must be removed. Instead just copy the relevant portion and
save one memmove operation.

Change-Id: I24b938a6f5fac5a23cd0132aefe9ce258b352ef8
Reviewed-on: https://code.wireshark.org/review/36342
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Mikael Kanstrup 2020-03-03 08:48:47 +01:00 committed by Anders Broman
parent a413802052
commit d24a11ee2e
1 changed files with 5 additions and 6 deletions

View File

@ -1231,17 +1231,16 @@ Dot11DecryptRsnaMng(
return DOT11DECRYPT_RET_UNSUCCESS;
}
/* copy the decrypted data into the decrypt buffer GCS*/
memcpy(decrypt_data, try_data, *decrypt_len);
g_free(try_data);
/* remove protection bit */
decrypt_data[1]&=0xBF;
/* remove TKIP/CCMP header */
*decrypt_len-=8;
memmove(decrypt_data + mac_header_len,
decrypt_data + mac_header_len + 8, *decrypt_len - mac_header_len);
/* copy the decrypted data into the decrypt buffer GCS*/
memcpy(decrypt_data + mac_header_len, try_data + mac_header_len + 8,
*decrypt_len - mac_header_len);
g_free(try_data);
Dot11DecryptCopyKey(sa, key);
return DOT11DECRYPT_RET_SUCCESS;