DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 3/5] examples: set correct limit for length of unix socket path
Date: Tue, 16 Dec 2014 15:03:51 +0000	[thread overview]
Message-ID: <1418742233-16776-4-git-send-email-bruce.richardson@intel.com> (raw)
In-Reply-To: <1418742233-16776-1-git-send-email-bruce.richardson@intel.com>

The length of the path to a unix socket is not PATH_MAX but instead is
UNIX_PATH_MAX which is generally just over 100 bytes in size. It's not
actually defined in sys/un.h on linux - despite the man page referencing
it, so calculate the size in the case where it's not defined.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 examples/vm_power_manager/channel_manager.c | 2 +-
 examples/vm_power_manager/channel_manager.h | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 7828be7..34a395d 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -597,7 +597,7 @@ get_info_vm(const char *vm_name, struct vm_info *info)
 	ITERATIVE_BITMASK_CHECK_64(mask, i) {
 		info->channels[channel_num].channel_num = i;
 		memcpy(info->channels[channel_num].channel_path,
-				vm_info->channels[i]->channel_path, PATH_MAX);
+				vm_info->channels[i]->channel_path, UNIX_PATH_MAX);
 		info->channels[channel_num].status = vm_info->channels[i]->status;
 		info->channels[channel_num].fd = vm_info->channels[i]->fd;
 		channel_num++;
diff --git a/examples/vm_power_manager/channel_manager.h b/examples/vm_power_manager/channel_manager.h
index 12c29c3..67e26ec 100644
--- a/examples/vm_power_manager/channel_manager.h
+++ b/examples/vm_power_manager/channel_manager.h
@@ -39,6 +39,7 @@ extern "C" {
 #endif
 
 #include <linux/limits.h>
+#include <sys/un.h>
 #include <rte_atomic.h>
 #include "channel_commands.h"
 
@@ -54,6 +55,11 @@ extern "C" {
 /* File socket directory */
 #define CHANNEL_MGR_SOCKET_PATH     "/tmp/powermonitor/"
 
+#ifndef UNIX_PATH_MAX
+struct sockaddr_un _sockaddr_un;
+#define UNIX_PATH_MAX sizeof(_sockaddr_un.sun_path)
+#endif
+
 /* Communication Channel Status */
 enum channel_status { CHANNEL_MGR_CHANNEL_DISCONNECTED = 0,
 	CHANNEL_MGR_CHANNEL_CONNECTED,
@@ -68,7 +74,7 @@ enum vm_status { CHANNEL_MGR_VM_INACTIVE = 0, CHANNEL_MGR_VM_ACTIVE};
  *  the host.
  */
 struct channel_info {
-	char channel_path[PATH_MAX]; /**< Path to host socket */
+	char channel_path[UNIX_PATH_MAX]; /**< Path to host socket */
 	volatile uint32_t status;    /**< Connection status(enum channel_status) */
 	int fd;                      /**< AF_UNIX socket fd */
 	unsigned channel_num;        /**< CHANNEL_MGR_SOCKET_PATH/<vm_name>.channel_num */
-- 
1.9.3

  parent reply	other threads:[~2014-12-16 15:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-16 15:03 [dpdk-dev] [PATCH 0/5] Fixes for issues highlighted by static analysis scan Bruce Richardson
2014-12-16 15:03 ` [dpdk-dev] [PATCH 1/5] test: after NULL check, don't free the NULL pointer Bruce Richardson
2014-12-16 15:03 ` [dpdk-dev] [PATCH 2/5] test: check for mbuf alloc failure Bruce Richardson
2014-12-16 15:03 ` Bruce Richardson [this message]
2014-12-16 15:03 ` [dpdk-dev] [PATCH 4/5] examples: fix check for null before de-reference Bruce Richardson
2014-12-16 15:03 ` [dpdk-dev] [PATCH 5/5] cfgfile: prevent error when reading an empty file Bruce Richardson
2014-12-16 23:53 ` [dpdk-dev] [PATCH 0/5] Fixes for issues highlighted by static analysis scan Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418742233-16776-4-git-send-email-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).