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

ZOOKEEPER-3726: invalid ipv6 address comparison #1252

Closed
wants to merge 3 commits into from

Conversation

vtyulb
Copy link
Contributor

@vtyulb vtyulb commented Feb 13, 2020

Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

@vtyulb vtyulb requested review from eolivelli and nkalmar February 17, 2020 08:43
@vtyulb
Copy link
Contributor Author

vtyulb commented Feb 17, 2020

@eolivelli @nkalmar

Hi guys, can you please review changes, or may be point me to some required actions?

@nkalmar
Copy link
Contributor

nkalmar commented Feb 26, 2020

LGTM, I have one question which I'm not sure about at all, just seems logical to me. (See my code comment)

Anyway, I would need someone else to also take a look, perhaps @symat who has more C experience.

@symat
Copy link
Contributor

symat commented Feb 27, 2020

LGTM in general, nice catch!

We already have similar logics here:

static const char* format_endpoint_info(const struct sockaddr_storage* ep)
{
static char buf[128] = { 0 };
char addrstr[INET6_ADDRSTRLEN] = { 0 };
const char *fmtstring;
void *inaddr;
char is_inet6 = 0; // poor man's boolean
#ifdef _WIN32
char * addrstring;
#endif
int port;
if(ep==0)
return "null";
#if defined(AF_INET6)
if(ep->ss_family==AF_INET6){
inaddr=&((struct sockaddr_in6*)ep)->sin6_addr;
port=((struct sockaddr_in6*)ep)->sin6_port;
is_inet6 = 1;
} else {
#endif
inaddr=&((struct sockaddr_in*)ep)->sin_addr;
port=((struct sockaddr_in*)ep)->sin_port;
#if defined(AF_INET6)
}
#endif
fmtstring = (is_inet6 ? "[%s]:%d" : "%s:%d");
#ifdef _WIN32
addrstring = inet_ntoa (*(struct in_addr*)inaddr);
sprintf(buf,fmtstring,addrstring,ntohs(port));
#else
inet_ntop(ep->ss_family,inaddr,addrstr,sizeof(addrstr)-1);
sprintf(buf,fmtstring,addrstr,ntohs(port));
#endif
return buf;
}

It would be great to add a unit test for it (both for IPv4 and IPv6), but it seems to be a complicated issue to reproduce with unit tests. Please think about it. But I am OK to commit this without tests as well.

@vtyulb
Copy link
Contributor Author

vtyulb commented Feb 28, 2020

Well, for sure it's almost impossible to reproduce full problem behavior. But it's possible to show how new addrvec_contains differs from the old one. In second commit I generate all addresses that differ by one bit from source. These tests can't pass on previous implementation.

Also, I found 2 duplicate tickets for my issue:
https://issues.apache.org/jira/browse/ZOOKEEPER-1677
https://issues.apache.org/jira/browse/ZOOKEEPER-2490

Both tickets have patches attached. ZOOKEEPER-2490 is not very elegant, but ZOOKEEPER-1677 even had tests (on which mine are based now). I am not really sure why they weren't merged, it looks like I am not the first one to encounter the bug.

@vtyulb
Copy link
Contributor Author

vtyulb commented Mar 5, 2020

@symat 7 years have passed since bug discovery, I think it's time to merge the fix.

@symat
Copy link
Contributor

symat commented Mar 5, 2020

agree, and I also like your unit tests, thanks for taking the time to implement them! :)
@anmolnar, @nkalmar, @eolivelli PTAL

Copy link
Contributor

@nkalmar nkalmar left a comment

Choose a reason for hiding this comment

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

Okay, LGTM!

@vtyulb
Copy link
Contributor Author

vtyulb commented Apr 11, 2020

please don't lose my PR @symat @nkalmar

@symat
Copy link
Contributor

symat commented Apr 11, 2020

Sure, thanks for the notification! I'll merge it on Tuesday, if noone else does before.

@symat
Copy link
Contributor

symat commented Apr 11, 2020

The kids woke up late, I think I can merge it now :)
I will push for master and branch-3.6, and also check it if I can also push on branch-3.5 without conflict.

@asfgit asfgit closed this in 726f684 Apr 11, 2020
@vtyulb
Copy link
Contributor Author

vtyulb commented Apr 11, 2020

Thank you!

asfgit pushed a commit that referenced this pull request Apr 11, 2020
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes #1252 from vtyulb/ZOOKEEPER-3726

(cherry picked from commit 726f684)
Signed-off-by: Mate Szalay-Beko <[email protected]>
asfgit pushed a commit that referenced this pull request Apr 11, 2020
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes #1252 from vtyulb/ZOOKEEPER-3726

(cherry picked from commit 726f684)
Signed-off-by: Mate Szalay-Beko <[email protected]>
@symat
Copy link
Contributor

symat commented Apr 11, 2020

I compiled and re-executed the C client tests on all branches (as this commit was tested by the CI a long time ago), everything seemed to be fine.

@vtyulb Thanks again for your help and your patience! :)

eolivelli pushed a commit that referenced this pull request Apr 19, 2020
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes #1252 from vtyulb/ZOOKEEPER-3726

(cherry picked from commit 726f684)
Signed-off-by: Mate Szalay-Beko <[email protected]>
stickyhipp pushed a commit to stickyhipp/zookeeper that referenced this pull request Aug 19, 2020
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes apache#1252 from vtyulb/ZOOKEEPER-3726
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes apache#1252 from vtyulb/ZOOKEEPER-3726
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes apache#1252 from vtyulb/ZOOKEEPER-3726
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes apache#1252 from vtyulb/ZOOKEEPER-3726
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Sep 3, 2022
Fix for https://issues.apache.org/jira/browse/ZOOKEEPER-3726

sockaddr_storage can contain ipv4 or ipv6 address. If address is ipv6, then we need to compare more bytes.

In this PR correct comparison of sockaddr_storage was added.

Author: Vladislav Tyulbashev <[email protected]>

Reviewers: Norbert Kalmar <[email protected]>, Mate Szalay-Beko <[email protected]>

Closes apache#1252 from vtyulb/ZOOKEEPER-3726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants