Skip to content

Commit aafeef7

Browse files
author
Veijo Pesonen
committed
gethostbyname won't accept empty name
Considers both versions - synchronous and asynchronous. Earlier the underlying stack was trusted to do this check.
1 parent 24cebba commit aafeef7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

features/netsocket/NetworkStack.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const char *NetworkStack::get_ip_address()
2828
}
2929
nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
3030
{
31+
if (name[0] == '\0') {
32+
return NSAPI_ERROR_PARAMETER;
33+
}
34+
3135
// check for simple ip addresses
3236
if (address->set_ip_address(name)) {
3337
if (version != NSAPI_UNSPEC && address->get_ip_version() != version) {
@@ -53,6 +57,10 @@ nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *name, hostb
5357
{
5458
SocketAddress address;
5559

60+
if (name[0] == '\0') {
61+
return NSAPI_ERROR_PARAMETER;
62+
}
63+
5664
// check for simple ip addresses
5765
if (address.set_ip_address(name)) {
5866
if (version != NSAPI_UNSPEC && address.get_ip_version() != version) {

0 commit comments

Comments
 (0)