Blame SOURCES/0004-quic-Avoid-possible-buffer-overflow-in-find_bucket.patch

199a67
From 57c6e6b00247ad289a27648213d7ad2306fe3931 Mon Sep 17 00:00:00 2001
199a67
From: Frediano Ziglio <freddy77@gmail.com>
199a67
Date: Thu, 30 Apr 2020 10:19:09 +0100
199a67
Subject: [PATCH spice-common 4/4] quic: Avoid possible buffer overflow in
199a67
 find_bucket
199a67
199a67
Proved by fuzzing the code.
199a67
199a67
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
199a67
Acked-by: Uri Lublin <uril@redhat.com>
199a67
---
199a67
 common/quic_family_tmpl.c | 7 ++++++-
199a67
 1 file changed, 6 insertions(+), 1 deletion(-)
199a67
199a67
diff --git a/subprojects/spice-common/common/quic_family_tmpl.c b/subprojects/spice-common/common/quic_family_tmpl.c
199a67
index 8a5f7d2..6cc051b 100644
199a67
--- a/subprojects/spice-common/common/quic_family_tmpl.c
199a67
+++ b/subprojects/spice-common/common/quic_family_tmpl.c
199a67
@@ -103,7 +103,12 @@ static s_bucket *FNAME(find_bucket)(Channel *channel, const unsigned int val)
199a67
         spice_assert(val < (0x1U << BPC));
199a67
     }
199a67
 
199a67
-    return channel->_buckets_ptrs[val];
199a67
+    /* The and (&) here is to avoid buffer overflows in case of garbage or malicious
199a67
+     * attempts. Is much faster then using comparisons and save us from such situations.
199a67
+     * Note that on normal build the check above won't be compiled as this code path
199a67
+     * is pretty hot and would cause speed regressions.
199a67
+     */
199a67
+    return channel->_buckets_ptrs[val & ((1U << BPC) - 1)];
199a67
 }
199a67
 
199a67
 #undef FNAME
199a67
-- 
199a67
2.25.4
199a67