Prevent crash in EncryptInPlace when the encrypter is missing
I'm currently investigating exactly what can cause this crash but I believe this could happen in production so I'd rather put this fix in now as a safety measure and build a repro test shortly after.
gfe-relnote: n/a, replace a crash with a QUIC_BUG
PiperOrigin-RevId: 243903209
Change-Id: I14403f3ed648c56f4d197b8d36e180639237dacb
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 583291e..0c65dc2 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -3940,6 +3940,14 @@
size_t buffer_len,
char* buffer) {
DCHECK(packet_number.IsInitialized());
+ if (encrypter_[level] == nullptr) {
+ QUIC_BUG << ENDPOINT
+ << "Attempted to encrypt in place without encrypter at level "
+ << QuicUtils::EncryptionLevelToString(level);
+ RaiseError(QUIC_ENCRYPTION_FAILURE);
+ return 0;
+ }
+
size_t output_length = 0;
if (!encrypter_[level]->EncryptPacket(
packet_number.ToUint64(),
@@ -3960,7 +3968,12 @@
char* buffer,
size_t buffer_len) {
DCHECK(packet_number.IsInitialized());
- DCHECK(encrypter_[level] != nullptr);
+ if (encrypter_[level] == nullptr) {
+ QUIC_BUG << ENDPOINT << "Attempted to encrypt without encrypter at level "
+ << QuicUtils::EncryptionLevelToString(level);
+ RaiseError(QUIC_ENCRYPTION_FAILURE);
+ return 0;
+ }
QuicStringPiece associated_data =
packet.AssociatedData(version_.transport_version);