Commit dabd8bf9 authored by Michael Tuexen's avatar Michael Tuexen
Browse files

libc sctp: fix sctp_getladdrs() for 64-bit BE platforms

When calling getsockopt() with SCTP_GET_LOCAL_ADDR_SIZE, use a
pointer to a 32-bit variable, since this is what the kernel
expects.
While there, do some cleanups.

MFC after:	1 week
parent a01b8859
......@@ -391,23 +391,23 @@ sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
{
struct sctp_getaddresses *addrs;
struct sockaddr *sa;
sctp_assoc_t asoc;
caddr_t lim;
socklen_t opt_len;
uint32_t size_of_addresses;
int cnt;
if (raddrs == NULL) {
errno = EFAULT;
return (-1);
}
asoc = id;
opt_len = (socklen_t)sizeof(sctp_assoc_t);
/* When calling getsockopt(), the value contains the assoc_id. */
size_of_addresses = (uint32_t)id;
opt_len = (socklen_t)sizeof(uint32_t);
if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_REMOTE_ADDR_SIZE,
&asoc, &opt_len) != 0) {
&size_of_addresses, &opt_len) != 0) {
return (-1);
}
/* size required is returned in 'asoc' */
opt_len = (socklen_t)((size_t)asoc + sizeof(struct sctp_getaddresses));
opt_len = (socklen_t)((size_t)size_of_addresses + sizeof(struct sctp_getaddresses));
addrs = calloc(1, (size_t)opt_len);
if (addrs == NULL) {
errno = ENOMEM;
......@@ -446,10 +446,10 @@ int
sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
{
struct sctp_getaddresses *addrs;
caddr_t lim;
struct sockaddr *sa;
size_t size_of_addresses;
caddr_t lim;
socklen_t opt_len;
uint32_t size_of_addresses;
int cnt;
if (raddrs == NULL) {
......@@ -457,7 +457,7 @@ sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
return (-1);
}
size_of_addresses = 0;
opt_len = (socklen_t)sizeof(int);
opt_len = (socklen_t)sizeof(uint32_t);
if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDR_SIZE,
&size_of_addresses, &opt_len) != 0) {
errno = ENOMEM;
......@@ -467,7 +467,7 @@ sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
errno = ENOTCONN;
return (-1);
}
opt_len = (socklen_t)(size_of_addresses + sizeof(struct sctp_getaddresses));
opt_len = (socklen_t)((size_t)size_of_addresses + sizeof(struct sctp_getaddresses));
addrs = calloc(1, (size_t)opt_len);
if (addrs == NULL) {
errno = ENOMEM;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment