os/net/netdev: Fix a bug in copy address info
When addrinfo structure has no canon name, skip copying it for safety
@@ -1109,6 +1109,7 @@ static struct addrinfo *copy_addrinfo(struct addrinfo *src)
dst->ai_socktype = tmp->ai_socktype;
dst->ai_protocol = tmp->ai_protocol;
dst->ai_addrlen = tmp->ai_addrlen;
+
dst->ai_addr = (struct sockaddr *)kumm_malloc(sizeof(struct sockaddr));
if (!dst->ai_addr) {
ndbg("copy_addrinfo() kumm_malloc failed\n");
@@ -1116,6 +1117,8 @@ static struct addrinfo *copy_addrinfo(struct addrinfo *src)
break;
}
memcpy(dst->ai_addr, tmp->ai_addr, sizeof(struct sockaddr));
+
+ if (tmp->ai_canonname) {
dst->ai_canonname = (char *)kumm_malloc(sizeof(tmp->ai_canonname));
if (!dst->ai_canonname) {
ndbg("copy_addrinfo() kumm_malloc failed\n");
@@ -1124,6 +1127,10 @@ static struct addrinfo *copy_addrinfo(struct addrinfo *src)
break;
}
memcpy(dst->ai_canonname, tmp->ai_canonname, sizeof(tmp->ai_canonname));
+ } else {
+ dst->ai_canonname = NULL;
+ }
+
dst->ai_next = NULL;
if (prev) {
prev->ai_next = dst;
