From 6f927c7c623f24684ed917c1a0afc89b0d2b77cb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 25 Sep 2019 13:59:19 +0100 Subject: [PATCH] [Minor] Avoid out-of-boundary read in btrie Submitted by: @citrin --- contrib/lc-btrie/btrie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/lc-btrie/btrie.c b/contrib/lc-btrie/btrie.c index b1c66f1c3..8b598b09b 100644 --- a/contrib/lc-btrie/btrie.c +++ b/contrib/lc-btrie/btrie.c @@ -658,7 +658,8 @@ static inline int prefixes_equal(const btrie_oct_t *pfx1, const btrie_oct_t *pfx2, unsigned len) { return (memcmp (pfx1, pfx2, len / 8) == 0 - && ((pfx1[len / 8] ^ pfx2[len / 8]) & high_bits (len % 8)) == 0); + && (len % 8 == 0 || + ((pfx1[len / 8] ^ pfx2[len / 8]) & high_bits (len % 8)) == 0)); } /* determine length of longest common subprefix */ -- 2.39.5