mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
cf-socket: tweak a memcpy() to read better
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
This commit is contained in:
parent
bc37765466
commit
e891b4195f
@ -333,12 +333,11 @@ static CURLcode sock_assign_addr(struct Curl_sockaddr_ex *dest,
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -48,11 +48,12 @@ struct Curl_sockaddr_ex {
|
||||
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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user