summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadoslaw Kaczorowski <external.radoslaw.kaczorowski@bosch-softtec.com>2019-06-17 11:19:22 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2019-07-03 11:48:10 +0900
commit646f76c58bc81b2d41163b2e9dfcf279ebd9e887 (patch)
tree81f1f4d9532e28ec006e71c268c739fd71e13828
parentb757183f51920e8445ed0ea0bbdb490d99781ec6 (diff)
downloadDLT-daemon-646f76c58bc81b2d41163b2e9dfcf279ebd9e887.tar.gz
define DLT_PATH_MAX for max path buffer length
DLT limits the path length and does not do anything else to determine the actual value, because the least that is supported on any system that DLT runs on is 1024 bytes. Signed-off-by: Vo Trung Chi <Chi.VoTrung@vn.bosch.com>
-rw-r--r--include/dlt/dlt_common.h10
-rw-r--r--src/daemon/dlt-daemon.c19
-rw-r--r--src/daemon/dlt-daemon.h4
-rw-r--r--src/lib/dlt_user.c22
-rw-r--r--src/shared/dlt_common.c8
5 files changed, 38 insertions, 25 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index acc1135..e41fa5c 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -350,6 +350,14 @@ enum {
# define DLT_RCV_REMOVE (1 << 1)
/**
+ * Maximal length of path in DLT
+ * DLT limits the path length and does not do anything else to determine
+ * the actual value, because the least that is supported on any system
+ * that DLT runs on is 1024 bytes.
+ */
+# define DLT_PATH_MAX 1024
+
+/**
* Maximal length of mounted path
*/
# define DLT_MOUNT_PATH_MAX 1024
@@ -413,7 +421,7 @@ extern char dltSerialHeaderChar[DLT_ID_SIZE];
/**
* The common base-path of the dlt-daemon-fifo and application-generated fifos
*/
-extern char dltFifoBaseDir[PATH_MAX + 1];
+extern char dltFifoBaseDir[DLT_PATH_MAX];
/**
* The type of a DLT ID (context id, application id, etc.)
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 9144b2a..50e178c 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -130,7 +130,8 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
/* default values */
daemon_local->flags.port = DLT_DAEMON_TCP_PORT;
- strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, sizeof(DLT_USER_IPC_PATH));
+ strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, DLT_PATH_MAX);
+ dltFifoBaseDir[DLT_PATH_MAX - 1] = 0;
opterr = 0;
@@ -148,7 +149,8 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
}
case 't':
{
- strncpy(dltFifoBaseDir, optarg, NAME_MAX);
+ strncpy(dltFifoBaseDir, optarg, DLT_PATH_MAX);
+ dltFifoBaseDir[DLT_PATH_MAX - 1] = 0;
break;
}
case 'p':
@@ -189,9 +191,11 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
#ifndef DLT_USE_UNIX_SOCKET_IPC
- snprintf(daemon_local->flags.userPipesDir, NAME_MAX + 1, "%s/dltpipes", dltFifoBaseDir);
+ snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
+ "%s/dltpipes", dltFifoBaseDir);
#endif
- snprintf(daemon_local->flags.daemonFifoName, NAME_MAX + 1, "%s/dlt", dltFifoBaseDir);
+ snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
+ "%s/dlt", dltFifoBaseDir);
return 0;
@@ -220,10 +224,9 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
snprintf(daemon_local->flags.loggingFilename,
- sizeof(daemon_local->flags.loggingFilename) - 1,
+ sizeof(daemon_local->flags.loggingFilename),
"%s/dlt.log",
dltFifoBaseDir);
- daemon_local->flags.loggingFilename[sizeof(daemon_local->flags.loggingFilename) - 1] = 0;
daemon_local->timeoutOnSend = 4;
daemon_local->RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE;
daemon_local->RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE;
@@ -1296,9 +1299,9 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i
void dlt_daemon_exit_trigger()
{
- char tmp[PATH_MAX + 1] = { 0 };
+ char tmp[DLT_PATH_MAX] = { 0 };
- snprintf(tmp, PATH_MAX, "%s/dlt", dltFifoBaseDir);
+ snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
(void)unlink(tmp);
/* stop event loop */
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index c813b42..2f8f814 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -122,9 +122,9 @@ typedef struct
#ifdef DLT_USE_UNIX_SOCKET_IPC
char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */
#else
- char userPipesDir[NAME_MAX + 1]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
+ char userPipesDir[DLT_PATH_MAX]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
#endif
- char daemonFifoName[NAME_MAX + 1]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
+ char daemonFifoName[DLT_PATH_MAX]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
unsigned int port; /**< port number */
char ctrlSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to Control socket */
int gatewayMode; /**< (Boolean) Gateway Mode */
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index e0939b1..cab3223 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -83,8 +83,8 @@ static bool dlt_user_initialised = false;
static int dlt_user_freeing = 0;
#ifndef DLT_USE_UNIX_SOCKET_IPC
-static char dlt_user_dir[NAME_MAX + 1];
-static char dlt_daemon_fifo[NAME_MAX + 1];
+static char dlt_user_dir[DLT_PATH_MAX];
+static char dlt_daemon_fifo[DLT_PATH_MAX];
#endif
static sem_t dlt_mutex;
@@ -230,7 +230,7 @@ static DltReturnValue dlt_initialize_socket_connection(void)
remote.sun_family = AF_UNIX;
snprintf(dltSockBaseDir, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH);
- strncpy(remote.sun_path, dltSockBaseDir, sizeof(dltSockBaseDir));
+ strncpy(remote.sun_path, dltSockBaseDir, sizeof(remote.sun_path));
if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX)
dlt_vlog(LOG_INFO,
@@ -267,11 +267,11 @@ static DltReturnValue dlt_initialize_socket_connection(void)
#else /* setup fifo*/
static DltReturnValue dlt_initialize_fifo_connection(void)
{
- char filename[DLT_USER_MAX_FILENAME_LENGTH];
+ char filename[DLT_PATH_MAX];
int ret;
- snprintf(dlt_user_dir, NAME_MAX, "%s/dltpipes", dltFifoBaseDir);
- snprintf(dlt_daemon_fifo, NAME_MAX, "%s/dlt", dltFifoBaseDir);
+ snprintf(dlt_user_dir, DLT_PATH_MAX, "%s/dltpipes", dltFifoBaseDir);
+ snprintf(dlt_daemon_fifo, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
ret = mkdir(dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX);
if ((ret == -1) && (errno != EEXIST)) {
@@ -293,7 +293,7 @@ static DltReturnValue dlt_initialize_fifo_connection(void)
}
/* create and open DLT user FIFO */
- snprintf(filename, DLT_USER_MAX_FILENAME_LENGTH, "%s/dlt%d", dlt_user_dir, getpid());
+ snprintf(filename, DLT_PATH_MAX, "%s/dlt%d", dlt_user_dir, getpid());
/* Try to delete existing pipe, ignore result of unlink */
unlink(filename);
@@ -354,7 +354,9 @@ DltReturnValue dlt_init(void)
return DLT_RETURN_ERROR;
}
- strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, sizeof(DLT_USER_IPC_PATH));
+ strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, DLT_PATH_MAX);
+ dltFifoBaseDir[DLT_PATH_MAX - 1] = 0;
+
/* check environment variables */
dlt_check_envvar();
@@ -775,7 +777,7 @@ DltReturnValue dlt_free(void)
uint32_t i;
int ret = 0;
#ifndef DLT_USE_UNIX_SOCKET_IPC
- char filename[DLT_USER_MAX_FILENAME_LENGTH];
+ char filename[DLT_PATH_MAX];
#endif
if (dlt_user_freeing != 0)
@@ -799,7 +801,7 @@ DltReturnValue dlt_free(void)
if (dlt_user.dlt_user_handle != DLT_FD_INIT) {
close(dlt_user.dlt_user_handle);
dlt_user.dlt_user_handle = DLT_FD_INIT;
- snprintf(filename, DLT_USER_MAX_FILENAME_LENGTH, "%s/dlt%d", dlt_user_dir, getpid());
+ snprintf(filename, DLT_PATH_MAX, "%s/dlt%d", dlt_user_dir, getpid());
unlink(filename);
}
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 4d6fcee..8f5bc76 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -67,7 +67,7 @@
const char dltSerialHeader[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 };
char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 };
-char dltFifoBaseDir[PATH_MAX + 1] = "/tmp";
+char dltFifoBaseDir[DLT_PATH_MAX] = "/tmp";
/* internal logging parameters */
static int logging_mode = DLT_LOG_TO_CONSOLE;
@@ -1701,8 +1701,8 @@ void dlt_log_set_filename(const char *filename)
void dlt_log_set_fifo_basedir(const char *env_pipe_dir)
{
- strncpy(dltFifoBaseDir, env_pipe_dir, PATH_MAX);
- dltFifoBaseDir[PATH_MAX] = 0;
+ strncpy(dltFifoBaseDir, env_pipe_dir, DLT_PATH_MAX);
+ dltFifoBaseDir[DLT_PATH_MAX - 1] = 0;
}
void dlt_log_init(int mode)
@@ -2495,7 +2495,7 @@ int dlt_buffer_push3(DltBuffer *buf,
}
/* set header */
- strncpy(head.head, DLT_BUFFER_HEAD, 3);
+ strncpy(head.head, DLT_BUFFER_HEAD, 4);
head.head[3] = 0;
head.status = 2;
head.size = size1 + size2 + size3;