[Pkg-iscsi-maintainers] [open-iscsi] 07/33: iscsid, iscsiadm: fix abstract socket length in bind() call

Ritesh Raj Sarraf rrs at alioth.debian.org
Tue Nov 5 16:21:11 UTC 2013


This is an automated email from the git hooks/post-receive script.

rrs pushed a commit to branch upstream-mnc
in repository open-iscsi.

commit 2d086a831dc16d10729d6fce17bed3ade3efd16c
Author: Tomasz Torcz <tomek at pipebreaker.pl>
Date:   Wed Nov 28 13:37:06 2012 +0100

    iscsid,iscsiadm: fix abstract socket length in bind() call
    
    For abstract sockets, the addrlen parameter should be the actual
    length of socket's name.  Otherwise socket gets padded with some
    number of NULs.
---
 usr/iscsid_req.c |   10 ++++++----
 usr/mgmt_ipc.c   |    9 +++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
index 0902011..1c4678d 100644
--- a/usr/iscsid_req.c
+++ b/usr/iscsid_req.c
@@ -56,7 +56,7 @@ static void iscsid_startup(void)
 
 static int iscsid_connect(int *fd, int start_iscsid)
 {
-	int nsec;
+	int nsec, addr_len;
 	struct sockaddr_un addr;
 
 	*fd = socket(AF_LOCAL, SOCK_STREAM, 0);
@@ -65,15 +65,17 @@ static int iscsid_connect(int *fd, int start_iscsid)
 		return ISCSI_ERR_ISCSID_NOTCONN;
 	}
 
+	addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
+
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
-		strlen(ISCSIADM_NAMESPACE));
+	memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
+
 	/*
 	 * Trying to connect with exponential backoff
 	 */
 	for (nsec = 1; nsec <= MAXSLEEP; nsec <<= 1) {
-		if (connect(*fd, (struct sockaddr *) &addr, sizeof(addr)) == 0)
+		if (connect(*fd, (struct sockaddr *) &addr, addr_len) == 0)
 			/* Connection established */
 			return ISCSI_SUCCESS;
 
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
index 5c39c2e..a1dafc9 100644
--- a/usr/mgmt_ipc.c
+++ b/usr/mgmt_ipc.c
@@ -43,7 +43,7 @@
 int
 mgmt_ipc_listen(void)
 {
-	int fd, err;
+	int fd, err, addr_len;
 	struct sockaddr_un addr;
 
 	fd = socket(AF_LOCAL, SOCK_STREAM, 0);
@@ -52,12 +52,13 @@ mgmt_ipc_listen(void)
 		return fd;
 	}
 
+	addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
+
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
-		strlen(ISCSIADM_NAMESPACE));
+	memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
 
-	if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0) {
+	if ((err = bind(fd, (struct sockaddr *) &addr, addr_len)) < 0 ) {
 		log_error("Can not bind IPC socket");
 		close(fd);
 		return err;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-iscsi/open-iscsi.git



More information about the Pkg-iscsi-maintainers mailing list