From: Heikki Linnakangas Date: Thu, 8 Oct 2009 04:47:06 +0000 (+0000) Subject: Fix off-by-one bug in bitncmp(): When comparing a number of bits divisible by X-Git-Tag: REL7_4_27~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f0e92290587b1536b80dc4a79e67cb9b541e9acb;p=postgresql Fix off-by-one bug in bitncmp(): When comparing a number of bits divisible by 8, bitncmp() may dereference a pointer one byte out of bounds. Chris Mikkelson (bug #5101) --- diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 496a8bf60e..33d12ec82c 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -1,7 +1,7 @@ /* * PostgreSQL type definitions for the INET and CIDR types. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.47.2.1 2003/12/01 18:50:29 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.47.2.2 2009/10/08 04:47:06 heikki Exp $ * * Jon Postel RIP 16 Oct 1998 */ @@ -874,7 +874,7 @@ bitncmp(void *l, void *r, int n) b = n / 8; x = memcmp(l, r, b); - if (x) + if (x || (n % 8) == 0) return (x); lb = ((const u_char *) l)[b];