php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Unify dns_*() function definitions for all platforms

Open RyanNerd opened this issue 4 years ago • 6 comments

Description

This is a todo in the code

I'm putting it here so it gets on the radar for a todo. If this is a wontfix then remove the todo from the code.

Changes to this code segment caused an issue #7748 with the output of gethostbyaddr() showing as a binary string in Windows.

/* TODO: Reimplement the gethostby* functions using the new winxp+ API, in dns_win32.c, then
 we can have a dns.c, dns_unix.c and dns_win32.c instead of a messy dns.c full of #ifdef
*/

RyanNerd avatar Jan 23 '22 02:01 RyanNerd

This comment confuses me. The implementation of the gethostby*() function looks reasonable; the implementation of the dns_*() functions appears to be the actual issue, since back then they have been implemented in dns_win32.c as full PHP functions, which already caused issues, because it's indeed easily overlooked that their implementation in dns.c is not the only one available. Improving this makes sense to me.

I wouldn't know, though, to which "new winxp+ API" the comment is referring. Maybe it's about using DnsQueryEx instead of DnsQuery, but the former is only available as of Windows 8/Server 2012.

cmb69 avatar Jan 23 '22 18:01 cmb69

The comment is 13 years old, so...

damianwadley avatar Jan 23 '22 18:01 damianwadley

Unassigning for time reasons; I hope to get back to this in a while, but wouldn't be sad, if somebody else beats me to it.

cmb69 avatar Feb 08 '22 11:02 cmb69

@cmb69 I wrote that if I remember correctly, in 5.3 windows port time.

What is the fixed issue exactly in the referred commit? I added a comment for @remicollet in the referred ticket, I don't really understand the use of getnameinfo for gethostbyaddr (which should really map what gethostbyaddr does :)

pierrejoye avatar Feb 12 '22 06:02 pierrejoye

This comment confuses me. The implementation of the gethostby*() function looks reasonable; the implementation of the dns_*() functions appears to be the actual issue, since back then they have been implemented in dns_win32.c as full PHP functions, which already caused issues,

It does not for 13 years. This was the only way to have clean codes somehow without massive functions full of #ifdef.

For what I see, the culprit is the change from getaddrinfo to getnameinfo for php_getaddrinfo, both functions do not behave the same and do not aim for the same features. Let see why it was changed then we can advise about the best fix :)

because it's indeed easily overlooked that their implementation in dns.c is not the only one available. Improving this makes sense to me.

pierrejoye avatar Feb 12 '22 06:02 pierrejoye

@pierrejoye, I think this is not particularly about the change from getaddrinfo to getnameinfo, but rather that we define the PHP functions in two different files. Few years ago there was a security issue related to the Windows implementation (NUL byte injection), that had already been fixed years ago for the Linux implementation. If the actual PHP function implementations are that different, it would still make sense to move them into a separate inlined C function.

cmb69 avatar Feb 14 '22 10:02 cmb69