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

inet_pton test in core/posix uses arbitrary hardcoded address families #3872

Closed
mmuman opened this issue Jul 26, 2016 · 4 comments
Closed

inet_pton test in core/posix uses arbitrary hardcoded address families #3872

mmuman opened this issue Jul 26, 2016 · 4 comments

Comments

@mmuman
Copy link
Contributor

mmuman commented Jul 26, 2016

In addition to passing NULL as buffers (which asserts Haiku's inet_pton()), the inet_pton test uses arbitrary hardcoded values to test error reporting, which can and actually do collide with some other tested values.
For example, AF_INET6 is 5 on Haiku.
And do we really need to test two of those?

If you really want to test with some other value, we could try AF_MAX, although on BSD it doesn't seem to be always defined (_BSD_VISIBLE) and when it is it actually is one of the possible values.
How about max(AF_INET, AF_INET6)+1 ?

It still seems fragile though, as it can still be a valid and actually implemented address family.
Also note that not all systems actually support (and even define) AF_INET6. MiNT (not the GNU/Linux distro!) comes to mind (but it does define AF_APPLETALK).

I'd propose some fallbacks from the least known family, something like:

#if defined(AF_DECnet)
#define AF_BAD AF_DECnet
#elif defined(AF_CHAOS)
#define AF_BAD AF_CHAOS
#elif defined(AF_APPLETALK)
#define AF_BAD AF_APPLETALK
#elif defined(AF_MAX)
#define AF_BAD AF_MAX
#else
#define AF_BAD (max(AF_INET, AF_INET6)+1)
#endif
@ethomson
Copy link
Member

Since inet_pton takes an int for the address family, I'm relatively sure that it's quite easy to come up with values that are unsupported everywhere, like INT_MAX-1 or -1.

In theory, we could also simply cl__skip this test on non-Windows, since the goal is to test our inet_pton implementation, and if the system implementation is broken then there's not much that we could do about it anyway. But it is quite nice to know that our implementation matches other platforms. So it is nice to have it running everywhere.

@mmuman
Copy link
Contributor Author

mmuman commented Jul 26, 2016

Yeah looks like I overengineered this one, INT_MAX-1 might do as well :)

@ethomson
Copy link
Member

Well, I overengineered the original, trying to be cute with chaosnet. 😀

@mmuman
Copy link
Contributor Author

mmuman commented Mar 23, 2017

Looks ok to me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants