Fix off-by-one bug in bitncmp(): When comparing a number of bits divisible by
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 8 Oct 2009 04:47:06 +0000 (04:47 +0000)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 8 Oct 2009 04:47:06 +0000 (04:47 +0000)
8, bitncmp() may dereference a pointer one byte out of bounds.

Chris Mikkelson (bug #5101)

src/backend/utils/adt/network.c

index 496a8bf60e29f45c6d1f44d16089df213b468943..33d12ec82cec79cf2941b280361596d1bb617dce 100644 (file)
@@ -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];