By checking the size of the actual buffer and using that as memcpy
target instead of another union member, this helps readers and static
code analyzers to determine that this is not a buffer overflow.
Ref: #18677
Closes #18787
}
dest->addrlen = (unsigned int)ai->ai_addrlen;
- if(dest->addrlen > sizeof(struct Curl_sockaddr_storage)) {
- DEBUGASSERT(0);
+ DEBUGASSERT(dest->addrlen <= sizeof(dest->curl_sa_addrbuf));
+ if(dest->addrlen > sizeof(dest->curl_sa_addrbuf))
return CURLE_TOO_LARGE;
- }
- memcpy(&dest->curl_sa_addr, ai->ai_addr, dest->addrlen);
+ memcpy(&dest->curl_sa_addrbuf, ai->ai_addr, dest->addrlen);
return CURLE_OK;
}
int protocol;
unsigned int addrlen;
union {
- struct sockaddr addr;
- struct Curl_sockaddr_storage buff;
- } _sa_ex_u;
+ struct sockaddr sa;
+ struct Curl_sockaddr_storage buf;
+ } addr;
};
-#define curl_sa_addr _sa_ex_u.addr
+#define curl_sa_addr addr.sa
+#define curl_sa_addrbuf addr.buf
/*
* Parse interface option, and return the interface name and the host part.