Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-30757 Fix IpAddress::ipincrement hostname bug #17999

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should hostname be clear here or still be text ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is, wherever it's an IP not a host (e.g. here), hostname is cleared, and getHostText falls back to getIpTest

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
Loading