Skip to content

Commit

Permalink
[SCTP] Fix leak in sctp_getsockopt_local_addrs when copy_to_user fails
Browse files Browse the repository at this point in the history
If the copy_to_user or copy_user calls fail in sctp_getsockopt_local_addrs(),
the function should free locally allocated storage before returning error.
Spotted by Coverity.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Acked-by: Sridhar Samudrala <sri@us.ibm.com>
  • Loading branch information
Vlad Yasevich authored and Vladislav Yasevich committed Jun 13, 2007
1 parent 8b35805 commit fe979ac
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -4352,11 +4352,12 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
err = -EFAULT;
goto error;
}
if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num))
return -EFAULT;
if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) {
err = -EFAULT;
goto error;
}
if (put_user(bytes_copied, optlen))
return -EFAULT;

err = -EFAULT;
error:
kfree(addrs);
return err;
Expand Down

0 comments on commit fe979ac

Please sign in to comment.