]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - iscsi-initiator-utils/patches/0007-iscsid-iscsiadm-fix-abstract-socket-length-in-bind-c.patch
iscsi-initiator-utils: Various improvements.
[people/ms/ipfire-3.x.git] / iscsi-initiator-utils / patches / 0007-iscsid-iscsiadm-fix-abstract-socket-length-in-bind-c.patch
CommitLineData
092b90ae
SS
1From 2d086a831dc16d10729d6fce17bed3ade3efd16c Mon Sep 17 00:00:00 2001
2From: Tomasz Torcz <tomek@pipebreaker.pl>
3Date: Wed, 28 Nov 2012 13:37:06 +0100
4Subject: iscsid,iscsiadm: fix abstract socket length in bind() call
5
6For abstract sockets, the addrlen parameter should be the actual
7length of socket's name. Otherwise socket gets padded with some
8number of NULs.
9---
10 usr/iscsid_req.c | 10 ++++++----
11 usr/mgmt_ipc.c | 9 +++++----
12 2 files changed, 11 insertions(+), 8 deletions(-)
13
14diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
15index 0902011..1c4678d 100644
16--- a/usr/iscsid_req.c
17+++ b/usr/iscsid_req.c
18@@ -56,7 +56,7 @@ static void iscsid_startup(void)
19
20 static int iscsid_connect(int *fd, int start_iscsid)
21 {
22- int nsec;
23+ int nsec, addr_len;
24 struct sockaddr_un addr;
25
26 *fd = socket(AF_LOCAL, SOCK_STREAM, 0);
27@@ -65,15 +65,17 @@ static int iscsid_connect(int *fd, int start_iscsid)
28 return ISCSI_ERR_ISCSID_NOTCONN;
29 }
30
31+ addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
32+
33 memset(&addr, 0, sizeof(addr));
34 addr.sun_family = AF_LOCAL;
35- memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
36- strlen(ISCSIADM_NAMESPACE));
37+ memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
38+
39 /*
40 * Trying to connect with exponential backoff
41 */
42 for (nsec = 1; nsec <= MAXSLEEP; nsec <<= 1) {
43- if (connect(*fd, (struct sockaddr *) &addr, sizeof(addr)) == 0)
44+ if (connect(*fd, (struct sockaddr *) &addr, addr_len) == 0)
45 /* Connection established */
46 return ISCSI_SUCCESS;
47
48diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
49index 5c39c2e..a1dafc9 100644
50--- a/usr/mgmt_ipc.c
51+++ b/usr/mgmt_ipc.c
52@@ -43,7 +43,7 @@
53 int
54 mgmt_ipc_listen(void)
55 {
56- int fd, err;
57+ int fd, err, addr_len;
58 struct sockaddr_un addr;
59
60 fd = socket(AF_LOCAL, SOCK_STREAM, 0);
61@@ -52,12 +52,13 @@ mgmt_ipc_listen(void)
62 return fd;
63 }
64
65+ addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
66+
67 memset(&addr, 0, sizeof(addr));
68 addr.sun_family = AF_LOCAL;
69- memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
70- strlen(ISCSIADM_NAMESPACE));
71+ memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
72
73- if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0) {
74+ if ((err = bind(fd, (struct sockaddr *) &addr, addr_len)) < 0 ) {
75 log_error("Can not bind IPC socket");
76 close(fd);
77 return err;
78--
791.7.11.7
80