summaryrefslogtreecommitdiff
path: root/Modules/getaddrinfo.c
diff options
context:
space:
mode:
authorRadek Smejkal <radek.smejkal@atrak.cz>2023-02-14 02:37:34 +0100
committerGitHub <noreply@github.com>2023-02-13 17:37:34 -0800
commit928752ce4c23f47d3175dd47ecacf08d86a99c9d (patch)
tree65124d98543829099a38f1d8fc8b33644a352de2 /Modules/getaddrinfo.c
parent0c6fe81dce9d6bb1dce5e4503f1b42bc5355ba24 (diff)
downloadcpython-git-928752ce4c23f47d3175dd47ecacf08d86a99c9d.tar.gz
gh-74895: getaddrinfo no longer raises OverflowError (#2435)
`socket.getaddrinfo()` no longer raises `OverflowError` based on the **port** argument. Error reporting (or not) for its value is left up to the underlying C library `getaddrinfo()` implementation.
Diffstat (limited to 'Modules/getaddrinfo.c')
-rw-r--r--Modules/getaddrinfo.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c
index 0b4620ed68..f1c28d7d93 100644
--- a/Modules/getaddrinfo.c
+++ b/Modules/getaddrinfo.c
@@ -342,7 +342,11 @@ getaddrinfo(const char*hostname, const char*servname,
pai->ai_socktype = SOCK_DGRAM;
pai->ai_protocol = IPPROTO_UDP;
}
- port = htons((u_short)atoi(servname));
+ long maybe_port = strtol(servname, NULL, 10);
+ if (maybe_port < 0 || maybe_port > 0xffff) {
+ ERR(EAI_SERVICE);
+ }
+ port = htons((u_short)maybe_port);
} else {
struct servent *sp;
const char *proto;