|
|
6c64be |
From 2d086a831dc16d10729d6fce17bed3ade3efd16c Mon Sep 17 00:00:00 2001
|
|
|
6c64be |
From: Tomasz Torcz <tomek@pipebreaker.pl>
|
|
|
6c64be |
Date: Wed, 28 Nov 2012 13:37:06 +0100
|
|
|
6c64be |
Subject: iscsid,iscsiadm: fix abstract socket length in bind() call
|
|
|
6c64be |
|
|
|
6c64be |
For abstract sockets, the addrlen parameter should be the actual
|
|
|
6c64be |
length of socket's name. Otherwise socket gets padded with some
|
|
|
6c64be |
number of NULs.
|
|
|
6c64be |
---
|
|
|
6c64be |
usr/iscsid_req.c | 10 ++++++----
|
|
|
6c64be |
usr/mgmt_ipc.c | 9 +++++----
|
|
|
6c64be |
2 files changed, 11 insertions(+), 8 deletions(-)
|
|
|
6c64be |
|
|
|
6c64be |
diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
|
|
|
6c64be |
index 0902011..1c4678d 100644
|
|
|
6c64be |
--- a/usr/iscsid_req.c
|
|
|
6c64be |
+++ b/usr/iscsid_req.c
|
|
|
6c64be |
@@ -56,7 +56,7 @@ static void iscsid_startup(void)
|
|
|
6c64be |
|
|
|
6c64be |
static int iscsid_connect(int *fd, int start_iscsid)
|
|
|
6c64be |
{
|
|
|
6c64be |
- int nsec;
|
|
|
6c64be |
+ int nsec, addr_len;
|
|
|
6c64be |
struct sockaddr_un addr;
|
|
|
6c64be |
|
|
|
6c64be |
*fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
6c64be |
@@ -65,15 +65,17 @@ static int iscsid_connect(int *fd, int start_iscsid)
|
|
|
6c64be |
return ISCSI_ERR_ISCSID_NOTCONN;
|
|
|
6c64be |
}
|
|
|
6c64be |
|
|
|
6c64be |
+ addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
|
|
|
6c64be |
+
|
|
|
6c64be |
memset(&addr, 0, sizeof(addr));
|
|
|
6c64be |
addr.sun_family = AF_LOCAL;
|
|
|
6c64be |
- memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
|
|
|
6c64be |
- strlen(ISCSIADM_NAMESPACE));
|
|
|
6c64be |
+ memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
|
|
|
6c64be |
+
|
|
|
6c64be |
/*
|
|
|
6c64be |
* Trying to connect with exponential backoff
|
|
|
6c64be |
*/
|
|
|
6c64be |
for (nsec = 1; nsec <= MAXSLEEP; nsec <<= 1) {
|
|
|
6c64be |
- if (connect(*fd, (struct sockaddr *) &addr, sizeof(addr)) == 0)
|
|
|
6c64be |
+ if (connect(*fd, (struct sockaddr *) &addr, addr_len) == 0)
|
|
|
6c64be |
/* Connection established */
|
|
|
6c64be |
return ISCSI_SUCCESS;
|
|
|
6c64be |
|
|
|
6c64be |
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
|
|
|
6c64be |
index 5c39c2e..a1dafc9 100644
|
|
|
6c64be |
--- a/usr/mgmt_ipc.c
|
|
|
6c64be |
+++ b/usr/mgmt_ipc.c
|
|
|
6c64be |
@@ -43,7 +43,7 @@
|
|
|
6c64be |
int
|
|
|
6c64be |
mgmt_ipc_listen(void)
|
|
|
6c64be |
{
|
|
|
6c64be |
- int fd, err;
|
|
|
6c64be |
+ int fd, err, addr_len;
|
|
|
6c64be |
struct sockaddr_un addr;
|
|
|
6c64be |
|
|
|
6c64be |
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
6c64be |
@@ -52,12 +52,13 @@ mgmt_ipc_listen(void)
|
|
|
6c64be |
return fd;
|
|
|
6c64be |
}
|
|
|
6c64be |
|
|
|
6c64be |
+ addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
|
|
|
6c64be |
+
|
|
|
6c64be |
memset(&addr, 0, sizeof(addr));
|
|
|
6c64be |
addr.sun_family = AF_LOCAL;
|
|
|
6c64be |
- memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
|
|
|
6c64be |
- strlen(ISCSIADM_NAMESPACE));
|
|
|
6c64be |
+ memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
|
|
|
6c64be |
|
|
|
6c64be |
- if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0) {
|
|
|
6c64be |
+ if ((err = bind(fd, (struct sockaddr *) &addr, addr_len)) < 0 ) {
|
|
|
6c64be |
log_error("Can not bind IPC socket");
|
|
|
6c64be |
close(fd);
|
|
|
6c64be |
return err;
|
|
|
6c64be |
--
|
|
|
6c64be |
1.7.11.7
|
|
|
6c64be |
|