Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 May 2014 18:23:57 +0000 (UTC)
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r266069 - stable/9/lib/libc/net
Message-ID:  <201405141823.s4EINv1S075070@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tuexen
Date: Wed May 14 18:23:57 2014
New Revision: 266069
URL: http://svnweb.freebsd.org/changeset/base/266069

Log:
  MFC r260257:
  
  Fix several bugs in sctp_bindx():
  * Set errno to EAFNOSUPPORT if an address is provided which is neither
    AF_INET nor AF_INET6.
  * Don't modify the arguments.
  * Don't smash the stack when provided with a non-zero port.
  * Handle the case correctly where the first address provided is
    an IPv6 address.

Modified:
  stable/9/lib/libc/net/sctp_sys_calls.c
Directory Properties:
  stable/9/lib/   (props changed)
  stable/9/lib/libc/   (props changed)

Modified: stable/9/lib/libc/net/sctp_sys_calls.c
==============================================================================
--- stable/9/lib/libc/net/sctp_sys_calls.c	Wed May 14 18:22:11 2014	(r266068)
+++ stable/9/lib/libc/net/sctp_sys_calls.c	Wed May 14 18:23:57 2014	(r266069)
@@ -233,19 +233,11 @@ sctp_bindx(int sd, struct sockaddr *addr
 			break;
 		default:
 			/* Invalid address family specified. */
-			errno = EINVAL;
+			errno = EAFNOSUPPORT;
 			return (-1);
 		}
 		sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
 	}
-	/*
-	 * Now if there was a port mentioned, assure that the first address
-	 * has that port to make sure it fails or succeeds correctly.
-	 */
-	if (sport) {
-		sin = (struct sockaddr_in *)sa;
-		sin->sin_port = sport;
-	}
 	argsz = sizeof(struct sctp_getaddresses) +
 	    sizeof(struct sockaddr_storage);
 	if ((gaddrs = (struct sctp_getaddresses *)malloc(argsz)) == NULL) {
@@ -257,6 +249,23 @@ sctp_bindx(int sd, struct sockaddr *addr
 		memset(gaddrs, 0, argsz);
 		gaddrs->sget_assoc_id = 0;
 		memcpy(gaddrs->addr, sa, sa->sa_len);
+		/*
+		 * Now, if there was a port mentioned, assure that the first
+		 * address has that port to make sure it fails or succeeds
+		 * correctly.
+		 */
+		if ((i == 0) && (sport != 0)) {
+			switch (gaddrs->addr->sa_family) {
+			case AF_INET:
+				sin = (struct sockaddr_in *)gaddrs->addr;
+				sin->sin_port = sport;
+				break;
+			case AF_INET6:
+				sin6 = (struct sockaddr_in6 *)gaddrs->addr;
+				sin6->sin6_port = sport;
+				break;
+			}
+		}
 		if (setsockopt(sd, IPPROTO_SCTP, flags, gaddrs,
 		    (socklen_t) argsz) != 0) {
 			free(gaddrs);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405141823.s4EINv1S075070>