Skip to content

Commit c5336a8

Browse files
committed
netmask() and hostmask() functions should return maximum-length masklen,
per gripe from Joe Sunday.
1 parent 3e5da0a commit c5336a8

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/backend/utils/adt/network.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* PostgreSQL type definitions for the INET and CIDR types.
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.48 2003/11/29 19:51:59 pgsql Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.49 2003/12/01 18:50:19 tgl Exp $
55
*
66
* Jon Postel RIP 16 Oct 1998
77
*/
@@ -315,8 +315,8 @@ inet_set_masklen(PG_FUNCTION_ARGS)
315315
errmsg("invalid mask length: %d", bits)));
316316

317317
/* clone the original data */
318-
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
319-
memcpy(dst, src, VARHDRSZ + sizeof(inet_struct));
318+
dst = (inet *) palloc(VARSIZE(src));
319+
memcpy(dst, src, VARSIZE(src));
320320

321321
ip_bits(dst) = bits;
322322

@@ -658,19 +658,13 @@ network_network(PG_FUNCTION_ARGS)
658658
inet *dst;
659659
int byte;
660660
int bits;
661-
int maxbytes;
662661
unsigned char mask;
663662
unsigned char *a,
664663
*b;
665664

666665
/* make sure any unused bits are zeroed */
667666
dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
668667

669-
if (ip_family(ip) == PGSQL_AF_INET)
670-
maxbytes = 4;
671-
else
672-
maxbytes = 16;
673-
674668
bits = ip_bits(ip);
675669
a = ip_addr(ip);
676670
b = ip_addr(dst);
@@ -710,18 +704,12 @@ network_netmask(PG_FUNCTION_ARGS)
710704
inet *dst;
711705
int byte;
712706
int bits;
713-
int maxbytes;
714707
unsigned char mask;
715708
unsigned char *b;
716709

717710
/* make sure any unused bits are zeroed */
718711
dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
719712

720-
if (ip_family(ip) == PGSQL_AF_INET)
721-
maxbytes = 4;
722-
else
723-
maxbytes = 16;
724-
725713
bits = ip_bits(ip);
726714
b = ip_addr(dst);
727715

@@ -744,7 +732,7 @@ network_netmask(PG_FUNCTION_ARGS)
744732
}
745733

746734
ip_family(dst) = ip_family(ip);
747-
ip_bits(dst) = ip_bits(ip);
735+
ip_bits(dst) = ip_maxbits(ip);
748736
ip_type(dst) = 0;
749737
VARATT_SIZEP(dst) = VARHDRSZ
750738
+ ((char *) ip_addr(dst) - (char *) VARDATA(dst))
@@ -794,7 +782,7 @@ network_hostmask(PG_FUNCTION_ARGS)
794782
}
795783

796784
ip_family(dst) = ip_family(ip);
797-
ip_bits(dst) = ip_bits(ip);
785+
ip_bits(dst) = ip_maxbits(ip);
798786
ip_type(dst) = 0;
799787
VARATT_SIZEP(dst) = VARHDRSZ
800788
+ ((char *) ip_addr(dst) - (char *) VARDATA(dst))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy