diff options
author | Tomasz Torcz <tomek@pipebreaker.pl> | 2012-11-28 13:37:06 +0100 |
---|---|---|
committer | Mike Christie <michaelc@cs.wisc.edu> | 2012-12-14 12:29:57 -0600 |
commit | 2d086a831dc16d10729d6fce17bed3ade3efd16c (patch) | |
tree | feadee51faf1ce6fc2fd6287ef45f73ab684b027 /usr/iscsid_req.c | |
parent | 97db3db45c7e96888ea48a54ff19b7ff5d08cca6 (diff) | |
download | open-iscsi-2d086a831dc16d10729d6fce17bed3ade3efd16c.tar.gz |
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.
Diffstat (limited to 'usr/iscsid_req.c')
-rw-r--r-- | usr/iscsid_req.c | 10 |
1 files changed, 6 insertions, 4 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; |