To avoid issues with race conditions involving separate addData() and result() calls use a method that does both in the lock.
Showing the changes to libraries/networking/src/NLPacket.cpp (1 of 3 files). Show all
Unified · Split
| @@ -157,9 +157,10 @@ QByteArray NLPacket::hashForPacketAndHMAC(const udt::Packet& packet, HMACAuth& h · 156 unmodified lines | |||
| 157 | + NUM_BYTES_LOCALID + NUM_BYTES_MD5_HASH; | 157 | + NUM_BYTES_LOCALID + NUM_BYTES_MD5_HASH; |
| 158 | 158 | ||
| 159 | // add the packet payload and the connection UUID | 159 | // add the packet payload and the connection UUID |
| 160 | QMutexLocker hashLock(&hash.getLock()); | 160 | HMACAuth::HMACHash hashResult; |
| 161 | hash.addData(packet.getData() + offset, packet.getDataSize() - offset); | 161 | if (!hash.calculateHash(hashResult, packet.getData() + offset, packet.getDataSize() - offset)) { |
| 162 | auto hashResult { hash.result() }; | 162 | return QByteArray(); |
| 163 | } | ||
| 163 | return QByteArray((const char*) hashResult.data(), (int) hashResult.size()); | 164 | return QByteArray((const char*) hashResult.data(), (int) hashResult.size()); |
| 164 | } | 165 | } |
| 165 | 166 | ||