Skip to content

Commit

Permalink
sctp: fix error return code in sctp_sendmsg_new_asoc()
Browse files Browse the repository at this point in the history
Return error code -EINVAL in the address len check error handling
case since 'err' can be overwrite to 0 by 'err = sctp_verify_addr()'
in the for loop.

Fixes: 2c0dbaa ("sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg")
Signed-off-by: Wei Yongjun <[email protected]>
Acked-by: Neil Horman <[email protected]>
Reviewed-by: Xin Long <[email protected]>
Acked-by: Neil Horman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Wei Yongjun authored and davem330 committed Mar 13, 2018
1 parent 7083a45 commit d98985d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
struct sctp_association *asoc;
enum sctp_scope scope;
struct cmsghdr *cmsg;
int err = -EINVAL;
int err;

*tp = NULL;

Expand Down Expand Up @@ -1761,16 +1761,20 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
memset(daddr, 0, sizeof(*daddr));
dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
if (dlen < sizeof(struct in_addr))
if (dlen < sizeof(struct in_addr)) {
err = -EINVAL;
goto free;
}

dlen = sizeof(struct in_addr);
daddr->v4.sin_family = AF_INET;
daddr->v4.sin_port = htons(asoc->peer.port);
memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
} else {
if (dlen < sizeof(struct in6_addr))
if (dlen < sizeof(struct in6_addr)) {
err = -EINVAL;
goto free;
}

dlen = sizeof(struct in6_addr);
daddr->v6.sin6_family = AF_INET6;
Expand Down

0 comments on commit d98985d

Please sign in to comment.