diff options
author | Brendan Coles <bcoles@gmail.com> | 2021-04-13 07:11:21 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-13 15:10:14 +0200 |
commit | ce010de74f8f9dfd27b7de4012c5783ca3718dc6 (patch) | |
tree | 2cea2104b6f4d9b37dd05b4308df7cbd7b347ac0 /Userland/Libraries/LibC/netdb.cpp | |
parent | bf1ef6533c75a4e63a99bdaf8f0bf5717496c194 (diff) | |
download | serenity-ce010de74f8f9dfd27b7de4012c5783ca3718dc6.zip |
LibC: getaddrinfo: Set addrinfo sin_port to 0 if service arg is NULL
Diffstat (limited to 'Userland/Libraries/LibC/netdb.cpp')
-rw-r--r-- | Userland/Libraries/LibC/netdb.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Libraries/LibC/netdb.cpp b/Userland/Libraries/LibC/netdb.cpp index 257bfc7431..f853c42be2 100644 --- a/Userland/Libraries/LibC/netdb.cpp +++ b/Userland/Libraries/LibC/netdb.cpp @@ -362,6 +362,9 @@ struct servent* getservent() struct servent* getservbyname(const char* name, const char* protocol) { + if (name == nullptr) + return nullptr; + bool previous_file_open_setting = keep_service_file_open; setservent(1); struct servent* current_service = nullptr; @@ -689,10 +692,14 @@ int getaddrinfo(const char* __restrict node, const char* __restrict service, con svc_ent = getservbyname(service, proto); } if (!svc_ent) { - char* end; - port = htons(strtol(service, &end, 10)); - if (*end) - return EAI_FAIL; + if (service) { + char* end; + port = htons(strtol(service, &end, 10)); + if (*end) + return EAI_FAIL; + } else { + port = htons(0); + } if (hints && hints->ai_socktype != 0) socktype = hints->ai_socktype; |