netsocket - Fix set_ip_bytes out-of-bound access

set_ip_bytes() does a 16-byte memcpy from the input buffer to
the local nsapi_addr_t despite the address version.

If the address version is ipv4, the input buffer may only be
4-byte in size. This causes a out-of-bound access on the input buffer.

Signed-off-by: Tony Wu <tonywu@realtek.com>
pull/3191/head
Tony Wu 2016-11-03 18:16:17 +08:00 committed by Tony Wu
parent d039d30abe
commit 70ad0f5226
1 changed files with 7 additions and 1 deletions

View File

@ -203,8 +203,14 @@ bool SocketAddress::set_ip_address(const char *addr)
void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version) void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
{ {
nsapi_addr_t addr; nsapi_addr_t addr;
addr = nsapi_addr_t();
addr.version = version; addr.version = version;
memcpy(addr.bytes, bytes, NSAPI_IP_BYTES); if (version == NSAPI_IPv6) {
memcpy(addr.bytes, bytes, NSAPI_IPv6_BYTES);
} else if (version == NSAPI_IPv4) {
memcpy(addr.bytes, bytes, NSAPI_IPv4_BYTES);
}
set_addr(addr); set_addr(addr);
} }