1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/paho-mqtt: don't copy addr_ip

ipvX_addr_from_str() takes a const pointer, it won't modify the address.
This commit is contained in:
Benjamin Valentin 2022-12-07 22:24:57 +01:00
parent 5986d8f371
commit 2a5bc04a16

View File

@ -120,18 +120,14 @@ int NetworkConnect(Network *n, char *addr_ip, int port)
{
int ret =-1;
sock_tcp_ep_t remote = SOCK_IPV4_EP_ANY;
char _local_ip[IP_MAX_LEN_ADDRESS];
strncpy(_local_ip, addr_ip, sizeof(_local_ip));
if (IS_USED(MODULE_IPV4_ADDR) &&
ipv4_addr_from_str((ipv4_addr_t *)&remote.addr, _local_ip)) {
if (IS_USED(MODULE_IPV4_ADDR) && (remote.port == 0) &&
ipv4_addr_from_str((ipv4_addr_t *)&remote.addr, addr_ip)) {
remote.port = port;
}
/* ipvN_addr_from_str modifies input buffer */
strncpy(_local_ip, addr_ip, sizeof(_local_ip));
if (IS_USED(MODULE_IPV6_ADDR) && (remote.port == 0) &&
ipv6_addr_from_str((ipv6_addr_t *)&remote.addr, _local_ip)) {
if (IS_USED(MODULE_IPV6_ADDR) && (remote.port == 0) &&
ipv6_addr_from_str((ipv6_addr_t *)&remote.addr, addr_ip)) {
remote.port = port;
remote.family = AF_INET6;
}