Skip to content

Commit 70ad0f5

Browse files
committed
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 <[email protected]>
1 parent d039d30 commit 70ad0f5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

features/netsocket/SocketAddress.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ bool SocketAddress::set_ip_address(const char *addr)
203203
void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
204204
{
205205
nsapi_addr_t addr;
206+
207+
addr = nsapi_addr_t();
206208
addr.version = version;
207-
memcpy(addr.bytes, bytes, NSAPI_IP_BYTES);
209+
if (version == NSAPI_IPv6) {
210+
memcpy(addr.bytes, bytes, NSAPI_IPv6_BYTES);
211+
} else if (version == NSAPI_IPv4) {
212+
memcpy(addr.bytes, bytes, NSAPI_IPv4_BYTES);
213+
}
208214
set_addr(addr);
209215
}
210216

0 commit comments

Comments
 (0)