]> granicus.if.org Git - postgresql/commitdiff
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:46:21 +0000 (04:46 +0000)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 8 Oct 2009 04:46:21 +0000 (04:46 +0000)
8, bitncmp() may dereference a pointer one byte out of bounds.

Chris Mikkelson (bug #5101)

src/backend/utils/adt/network.c

index f4fc67a84390af2a9e9facfc12327f023bf610c7..0ea13fc47bd33652b73524e9f3743baddede760f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     PostgreSQL type definitions for the INET and CIDR types.
  *
- *     $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.74 2009/06/11 14:49:03 momjian Exp $
+ *     $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.75 2009/10/08 04:46:21 heikki Exp $
  *
  *     Jon Postel RIP 16 Oct 1998
  */
@@ -972,7 +972,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];