[issue30710] getaddrinfo raises OverflowError
New submission from Radek Smejkal: If the port argument is a number, getaddrinfo attempts to convert it to a C long, that raises OverflowError if the conversion fails. Instead, getaddrinfo should convert the port to a string (bytes) directly and rely on the underlying getaddrinfo to return EAI_SERVICE. This is also consistent with the case when a numeric port is passed as a string. -- components: Library (Lib) messages: 296421 nosy: smejkar priority: normal severity: normal status: open title: getaddrinfo raises OverflowError type: behavior versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue30710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30711] getaddrinfo invalid port number
New submission from Radek Smejkal: Some getaddrinfo implementations do not detect invalid numeric services and blindly pass the port number to htons(). For example, service "960179" is returned as port 42675. glibc https://sourceware.org/bugzilla/show_bug.cgi?id=16208 https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/posix/getaddrinfo.c;h=a8bdd9a1829409bd797637b2c4fca4d67a11012d;hb=HEAD#l435 https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/posix/getaddrinfo.c;h=a8bdd9a1829409bd797637b2c4fca4d67a11012d;hb=HEAD#l2313 AIX 7.1 libc Broken Modules/getaddrinfo https://github.com/python/cpython/blob/master/Modules/getaddrinfo.c#L342 On the other hand, for example, OpenBSD and musl check the port range https://github.com/openbsd/src/blob/master/lib/libc/asr/getaddrinfo_async.c#L477 https://git.musl-libc.org/cgit/musl/tree/src/network/lookup_serv.c#n53 Modules/getaddrinfo should be fixed. The configure script should detect whether the system getaddrinfo is broken. If so, a wrapper that checks numeric services, and returns EAI_SERVICE or calls the system getaddrinfo should be used in place of the system getaddrinfo. -- components: Library (Lib) messages: 296423 nosy: smejkar priority: normal severity: normal status: open title: getaddrinfo invalid port number type: behavior versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue30711> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30710] getaddrinfo raises OverflowError
Radek Smejkal added the comment: Use PyObject_Str and PyUnicode_AsUTF8 if the port argument is a PyLong instead of converting it to an intermediate C long that may raise OverflowError. See getaddrinfo_overflow_error.patch -- components: +Extension Modules -Library (Lib) keywords: +patch Added file: http://bugs.python.org/file46964/getaddrinfo_overflow_error.patch ___ Python tracker <http://bugs.python.org/issue30710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30710] getaddrinfo raises OverflowError
Radek Smejkal added the comment: > But how large is the performance hit of this change? It adds at least one > additional memory allocation for the str object. If the slowdown is > significant perhaps it is worth to keep the old code as a fast path. commit 5cc7ac24da10568d2a910a91a24183b904118cf8 ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, 1000)' 2000 loops, best of 5: 139 usec per loop ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, "1000")' 2000 loops, best of 5: 142 usec per loop with getaddrinfo_overflow_error.patch ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, 1000)' 2000 loops, best of 5: 140 usec per loop ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, "1000")' 2000 loops, best of 5: 139 usec per loop It seems the impact on performance is negligible/not measurable. -- ___ Python tracker <http://bugs.python.org/issue30710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30710] getaddrinfo raises OverflowError
Radek Smejkal added the comment: > Why can't the user simply pass in a string service name in the first place? He/she can. But I don't propose to change that. The patch only changes the way a given number is converted to a string. That is, without an intermediate C long. -- ___ Python tracker <http://bugs.python.org/issue30710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30710] getaddrinfo raises OverflowError
Radek Smejkal added the comment: > I like your idea about getting rid of OverflowError. But wouldn't it make the > problem with other reported by you issue, issue30711, worse? It depends on the implementation of the underlying getaddrinfo. For Modules/getaddrinfo.c, it will be worse for positive numbers outside the C long range. -- ___ Python tracker <http://bugs.python.org/issue30710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30711] getaddrinfo invalid port number
Changes by Radek Smejkal : -- components: +Extension Modules -Library (Lib) keywords: +patch Added file: http://bugs.python.org/file46965/getaddrinfo_invalid_port.patch ___ Python tracker <http://bugs.python.org/issue30711> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30711] getaddrinfo invalid port number
Changes by Radek Smejkal : Removed file: http://bugs.python.org/file46965/getaddrinfo_invalid_port.patch ___ Python tracker <http://bugs.python.org/issue30711> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30711] getaddrinfo invalid port number
Radek Smejkal added the comment: See also issue30710. -- ___ Python tracker <http://bugs.python.org/issue30711> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30786] getaddrinfo emulation does not support AI_NUMERICSERV
New submission from Radek Smejkal: Modules/getaddrinfo.c should support AI_NUMERICSERV. Moreover, not supporting AI_NUMERICSERV may cause troubles on platforms where the getaddrinfo function is available but it's buggy (see configure.ac and Modules/socketmodule.c), because Modules/addrinfo.h does not #undef AI_NUMERICSERV and Modules/socketmodule.c exports AI_NUMERICSERV defined in a system header that may collide with another flag defined in Modules/addrinfo.h and confuse the user. ./configure --with-pydebug Comment out HAVE_GETADDRINFO in pyconfig.h Comment out ENABLE_IPV6 in pyconfig.h on platforms where getipnodebyname and friends are not available make -j ./python Python 3.7.0a0 (default, Jun 27 2017, 11:59:50) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> socket.AI_NUMERICSERV >>> socket.getaddrinfo(None, "http", flags=socket.AI_NUMERICSERV) Traceback (most recent call last): File "", line 1, in File "/home/radek/src/github/cpython/Lib/socket.py", line 743, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 3] invalid value for ai_flags. >>> -- components: Extension Modules messages: 297020 nosy: smejkar priority: normal severity: normal status: open title: getaddrinfo emulation does not support AI_NUMERICSERV type: behavior versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue30786> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30711] getaddrinfo invalid port number
Radek Smejkal added the comment: See also issue30786. -- ___ Python tracker <http://bugs.python.org/issue30711> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30710] getaddrinfo raises OverflowError
Changes by Radek Smejkal : -- pull_requests: +2483 ___ Python tracker <http://bugs.python.org/issue30710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30711] getaddrinfo invalid port number
Changes by Radek Smejkal : -- pull_requests: +2484 ___ Python tracker <http://bugs.python.org/issue30711> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30786] getaddrinfo emulation does not support AI_NUMERICSERV
Changes by Radek Smejkal : -- pull_requests: +2485 ___ Python tracker <http://bugs.python.org/issue30786> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com