[Open-FCoE] [PATCH 2/3] fcoe-utils: remove named unix socket between foceadm and fcoemon

Vasu Dev vasu.dev at intel.com
Wed Jan 19 19:58:37 UTC 2011


As named socket file could lead to name collision and requires
apps to unlink before exit, instead have kernel assign socket name
by not specifying sun_path during bind.

Signed-off-by: Vasu Dev <vasu.dev at intel.com>
Tested-by: Ross Brattain <ross.b.brattain at intel.com>
---

 fcoeadm.c |    9 ++-------
 fcoemon.c |    6 ++++--
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/fcoeadm.c b/fcoeadm.c
index 779b8d1..7644211 100644
--- a/fcoeadm.c
+++ b/fcoeadm.c
@@ -123,9 +123,8 @@ static enum fcoe_err fcoeadm_request(struct clif_sock_info *clif_info,
 	return rc;
 }
 
-static void fcoeadm_close_cli(struct clif_sock_info *clif_info)
+static inline void fcoeadm_close_cli(struct clif_sock_info *clif_info)
 {
-	unlink(clif_info->local.sun_path);
 	close(clif_info->socket_fd);
 }
 
@@ -143,11 +142,8 @@ static enum fcoe_err fcoeadm_open_cli(struct clif_sock_info *clif_info)
 	}
 
 	clif_info->local.sun_family = AF_UNIX;
-	snprintf(clif_info->local.sun_path, sizeof(clif_info->local.sun_path),
-		 "/tmp/fcadm_clif_%d", getpid());
-
 	if (bind(clif_info->socket_fd, (struct sockaddr *)&clif_info->local,
-		 sizeof(clif_info->local)) < 0) {
+		 sizeof(clif_info->local.sun_family)) < 0) {
 		rc = ENOMONCONN;
 		goto err_close;
 	}
@@ -159,7 +155,6 @@ static enum fcoe_err fcoeadm_open_cli(struct clif_sock_info *clif_info)
 	if (!connect(clif_info->socket_fd, (struct sockaddr *)&clif_info->dest,
 		     sizeof(clif_info->dest)) < 0) {
 		rc = ENOMONCONN;
-		unlink(clif_info->local.sun_path);
 		goto err_close;
 	}
 
diff --git a/fcoemon.c b/fcoemon.c
index 4842818..0114a82 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -2440,14 +2440,16 @@ static struct sock_info *fcm_alloc_reply(struct sockaddr_un *f,
 {
 	static struct sock_info *r;
 
+	if (flen > sizeof(*f))
+		return NULL;
+
 	r = (struct sock_info *)malloc(sizeof(struct sock_info));
 	if (!r) {
 		FCM_LOG_ERR(errno, "Failed in alloc reply sock info.\n");
 		return NULL;
 	}
 	r->sock = s;
-	r->from.sun_family = f->sun_family;
-	strncpy(r->from.sun_path, f->sun_path, sizeof(r->from.sun_path));
+	memcpy(&r->from, f, flen);
 	r->fromlen = flen;
 	return r;
 }




More information about the devel mailing list