Skip to content

Commit 0dcbb8b

Browse files
airweenFelipe Zimmerle
authored andcommitted
Fix inet addr handling on 64 bit big endian systems
Back port from v3. @zimmerle.
1 parent cb33bb4 commit 0dcbb8b

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

apache2/msc_tree.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
832832
switch(type) {
833833

834834
case IPV4_TREE:
835-
memset(&addr4, 0, sizeof(addr4));
835+
memset(&(addr4.s_addr), 0, sizeof(addr4.s_addr));
836836
memset(ip_strv4, 0x0, NETMASK_32);
837837

838838
strncpy(ip_strv4, buffer, sizeof(ip_strv4));
@@ -859,20 +859,16 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
859859
ip_strv4[pos] = '\0';
860860
}
861861

862-
ret = inet_pton(AF_INET, ip_strv4, &addr4);
862+
ret = inet_pton(AF_INET, ip_strv4, &(addr4.s_addr));
863863

864864
if (ret <= 0) {
865865
return NULL;
866866
}
867-
868-
ip = addr4.s_addr;
869-
870867
tree->count++;
871-
872-
return CPTAddElement((unsigned char *)&ip, NETMASK_32, tree, netmask_v4);
868+
return CPTAddElement((unsigned char *)&(addr4.s_addr), NETMASK_32, tree, netmask_v4);
873869

874870
case IPV6_TREE:
875-
memset(&addr6, 0, sizeof(addr6));
871+
memset(&(addr6.s6_addr), 0, sizeof(addr6.s6_addr));
876872
memset(ip_strv6, 0x0, NETMASK_128);
877873

878874
strncpy(ip_strv6, buffer, sizeof(ip_strv6));
@@ -899,7 +895,7 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
899895
ip_strv6[pos] = '\0';
900896
}
901897

902-
ret = inet_pton(AF_INET6, ip_strv6, &addr6);
898+
ret = inet_pton(AF_INET6, ip_strv6, &(addr6.s6_addr));
903899

904900
if (ret <= 0)
905901
{
@@ -908,10 +904,11 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
908904

909905
tree->count++;
910906

911-
return CPTAddElement((unsigned char *)&addr6.s6_addr, NETMASK_128, tree, netmask_v6);
907+
return CPTAddElement((unsigned char *)&(addr6.s6_addr), NETMASK_128, tree, netmask_v6);
912908
default:
913909
return NULL;
914910
}
915911

916912
return NULL;
917913
}
914+

apache2/msc_util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,26 +2712,26 @@ int tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
27122712
}
27132713

27142714
if (strchr(value, ':') == NULL) {
2715-
if (inet_pton(AF_INET, value, &in) <= 0) {
2715+
if (inet_pton(AF_INET, value, &(in.s_addr)) <= 0) {
27162716
*error_msg = apr_psprintf(mp, "IPmatch: bad IPv4 " \
27172717
"specification \"%s\".", value);
27182718
return -1;
27192719
}
27202720

2721-
if (CPTIpMatch(msr, (unsigned char *)&in.s_addr, rtree->ipv4_tree,
2721+
if (CPTIpMatch(msr, (unsigned char *)&(in.s_addr), rtree->ipv4_tree,
27222722
IPV4_TREE) != NULL) {
27232723
return 1;
27242724
}
27252725
}
27262726
#if APR_HAVE_IPV6
27272727
else {
2728-
if (inet_pton(AF_INET6, value, &in6) <= 0) {
2728+
if (inet_pton(AF_INET6, value, &(in6.s6_addr)) <= 0) {
27292729
*error_msg = apr_psprintf(mp, "IPmatch: bad IPv6 " \
27302730
"specification \"%s\".", value);
27312731
return -1;
27322732
}
27332733

2734-
if (CPTIpMatch(msr, (unsigned char *)&in6.s6_addr, rtree->ipv6_tree,
2734+
if (CPTIpMatch(msr, (unsigned char *)&(in6.s6_addr), rtree->ipv6_tree,
27352735
IPV6_TREE) != NULL) {
27362736
return 1;
27372737
}

0 commit comments

Comments
 (0)