about summary refs log tree commit diff
path: root/Src/Modules
diff options
context:
space:
mode:
authorAndrey Borzenkov <bor@users.sourceforge.net>2001-06-15 13:01:42 +0000
committerAndrey Borzenkov <bor@users.sourceforge.net>2001-06-15 13:01:42 +0000
commit12e1cf567d239495cf238f44456ab19daab327c8 (patch)
treeed060795e1751e2b69d0e809d5a57cbeeb51b986 /Src/Modules
parent87db19092061d3489ea2550ba1f54376d165b07a (diff)
downloadzsh-12e1cf567d239495cf238f44456ab19daab327c8.tar.gz
zsh-12e1cf567d239495cf238f44456ab19daab327c8.tar.xz
zsh-12e1cf567d239495cf238f44456ab19daab327c8.zip
14931: fix socket/address length calculation
Diffstat (limited to 'Src/Modules')
-rw-r--r--Src/Modules/tcp.c5
-rw-r--r--Src/Modules/zftp.c8
2 files changed, 8 insertions, 5 deletions
diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c
index 6f7a05cb2..7bd59fcce 100644
--- a/Src/Modules/tcp.c
+++ b/Src/Modules/tcp.c
@@ -255,6 +255,7 @@ tcp_close(Tcp_session sess)
 mod_export int
 tcp_connect(Tcp_session sess, char *addrp, struct hostent *zhost, int d_port)
 {
+    int salen;
 #ifdef SUPPORT_IPV6
     if(zhost->h_addrtype==AF_INET6) {
 	memcpy(&(sess->peer.in6.sin6_addr), addrp, zhost->h_length);
@@ -263,14 +264,16 @@ tcp_connect(Tcp_session sess, char *addrp, struct hostent *zhost, int d_port)
 # ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
 	sess->peer.in6.sin6_scope_id = 0;
 # endif
+	salen = sizeof(struct sockaddr_in6);
     } else
 #endif /* SUPPORT_IPV6 */
     {
 	memcpy(&(sess->peer.in.sin_addr), addrp, zhost->h_length);
 	sess->peer.in.sin_port = d_port;
+	salen = sizeof(struct sockaddr_in);
     }
 
-    return connect(sess->fd, (struct sockaddr *)&(sess->peer), zhost->h_length);
+    return connect(sess->fd, (struct sockaddr *)&(sess->peer), salen);
 }
 
 /* The load/unload routines required by the zsh library interface */
diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c
index 082c19781..e6fa9eb79 100644
--- a/Src/Modules/zftp.c
+++ b/Src/Modules/zftp.c
@@ -1699,7 +1699,7 @@ zftp_open(char *name, char **args, int flags)
     struct hostent *zhostp = NULL;
     char **addrp, *fname;
     int err, len, tmout;
-    int herrno, af, salen;
+    int herrno, af, hlen;
 
     if (!*args) {
 	if (zfsess->userparams)
@@ -1777,11 +1777,11 @@ zftp_open(char *name, char **args, int flags)
 	zfsess->control.peer.a.sa_family = af;
 #ifdef SUPPORT_IPV6
 	if(af == AF_INET6) {
-	    salen = sizeof(struct sockaddr_in6);
+	    hlen = 16;
 	} else
 #endif /* SUPPORT_IPV6 */
 	{
-	    salen = sizeof(struct sockaddr_in);
+	    hlen = 4;
 	}
 
 	tcp_socket(af, SOCK_STREAM, 0, &(zfsess->control));
@@ -1805,7 +1805,7 @@ zftp_open(char *name, char **args, int flags)
 
 	/* try all possible IP's */
 	for (addrp = zhostp->h_addr_list; err && *addrp; addrp++) {
-	    if(salen != zhostp->h_length)
+	    if(hlen != zhostp->h_length)
 		zwarnnam(name, "address length mismatch", NULL, 0);
 	    do {
 		err = tcp_connect(&(zfsess->control), *addrp, zhostp, zservp->s_port);