Skip to content

Commit

Permalink
HPCC-30757 Fix IpAddress::ipincrement hostname bug
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Smith <[email protected]>
  • Loading branch information
jakesmith authored and ghalliday committed Nov 8, 2023
1 parent 91bc0f6 commit c768c18
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions system/jlib/jsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,7 @@ inline bool isIp4(const unsigned *netaddr)

void IpAddress::setIP4(unsigned ip)
{
hostname.clear();
netaddr[0] = 0;
netaddr[1] = 0;
if (ip)
Expand Down Expand Up @@ -3596,25 +3597,32 @@ static bool lookupHostAddress(const char *name,unsigned *netaddr)

bool IpAddress::ipset(const char *text)
{
if (text&&*text) {
if ((text[0]=='.')&&(text[1]==0)) {
if (text&&*text)
{
if ((text[0]=='.')&&(text[1]==0))
{
ipset(queryHostIP());
return true;
}
hostname.set(text);
if (decodeNumericIP(text,netaddr))
{
hostname.clear();
return true;
}
const char *s;
for (s=text;*s;s++)
if (!isdigit(*s)&&(*s!=':')&&(*s!='.'))
break;
if (!*s)
return ipset(NULL);
if (lookupHostAddress(text,netaddr))
{
hostname.set(text);
return true;
}
}
memset(&netaddr,0,sizeof(netaddr));
hostname.clear();
memset(&netaddr,0,sizeof(netaddr));
return false;
}

Expand Down Expand Up @@ -3676,6 +3684,7 @@ void IpAddress::ipserialize(MemoryBuffer & out) const

void IpAddress::ipdeserialize(MemoryBuffer & in)
{
hostname.clear();
unsigned pfx;
in.read(sizeof(pfx),&pfx);
if (pfx!=IPV6_SERIALIZE_PREFIX) {
Expand Down Expand Up @@ -3736,6 +3745,7 @@ bool IpAddress::ipincrement(unsigned count,byte minoctet,byte maxoctet,unsigned
count = v/base;
}
}
hostname.clear(); // Probably should never be set for an IpAddress where ipincrement is used
return true;
}

Expand Down Expand Up @@ -3782,6 +3792,7 @@ NO_SANITIZE("alignment") size32_t IpAddress::getNetAddress(size32_t maxsz,void *

NO_SANITIZE("alignment") void IpAddress::setNetAddress(size32_t sz,const void *src)
{
hostname.clear();
if (sz==sizeof(unsigned)) { // IPv4
netaddr[0] = 0;
netaddr[1] = 0;
Expand Down

0 comments on commit c768c18

Please sign in to comment.