summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVo Trung Chi <chi.votrung@vn.bosch.com>2019-10-29 14:18:29 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2019-10-29 08:18:29 +0100
commit9011106fdaf5f66c232da371e426c52010771cbd (patch)
tree7993d785a2143bfb8d919d92f65d14fa9699f73c
parent1cabce7f04775990533bc8e066497e456350249a (diff)
downloadDLT-daemon-9011106fdaf5f66c232da371e426c52010771cbd.tar.gz
fix the dlt offline trace file name creation (#178)
The function dlt_offline_trace_file_name() use sizeof the pointer as the maximum file name size, so it cannot create the file name as expected. Signed-off-by: Vo Trung Chi <chi.votrung@vn.bosch.com>
-rw-r--r--include/dlt/dlt_offline_trace.h4
-rw-r--r--src/shared/dlt_offline_trace.c29
2 files changed, 19 insertions, 14 deletions
diff --git a/include/dlt/dlt_offline_trace.h b/include/dlt/dlt_offline_trace.h
index 58b14d4..7fcca0f 100644
--- a/include/dlt/dlt_offline_trace.h
+++ b/include/dlt/dlt_offline_trace.h
@@ -149,10 +149,12 @@ unsigned int dlt_offline_trace_storage_dir_info(char *path, char *file_name, cha
/**
* creates filename with index
* @param log_file_name file name created with index
+ * @param length the maximum length of the log_file_name
* @param name filename base
* @param idx index to be used for file name creation
*/
-void dlt_offline_trace_file_name(char *log_file_name, char *name, unsigned int idx);
+void dlt_offline_trace_file_name(char *log_file_name, size_t length,
+ char *name, unsigned int idx);
/**
* generates index for log file name
diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c
index 8fd1dc9..5eb49f5 100644
--- a/src/shared/dlt_offline_trace.c
+++ b/src/shared/dlt_offline_trace.c
@@ -138,17 +138,20 @@ unsigned int dlt_offline_trace_storage_dir_info(char *path, char *file_name, cha
return num;
}
-void dlt_offline_trace_file_name(char *log_file_name, char *name, unsigned int idx)
+void dlt_offline_trace_file_name(char *log_file_name, size_t length,
+ char *name, unsigned int idx)
{
char file_index[11]; /* UINT_MAX = 4294967295 -> 10 digits */
snprintf(file_index, sizeof(file_index), "%010u", idx);
/* create log file name */
- memset(log_file_name, 0, DLT_OFFLINETRACE_FILENAME_MAX_SIZE * sizeof(char));
- strncat(log_file_name, name, sizeof(log_file_name) - strlen(log_file_name) - 1);
- strncat(log_file_name, DLT_OFFLINETRACE_FILENAME_DELI, sizeof(log_file_name) - strlen(log_file_name) - 1);
- strncat(log_file_name, file_index, sizeof(log_file_name) - strlen(log_file_name) - 1);
- strncat(log_file_name, DLT_OFFLINETRACE_FILENAME_EXT, sizeof(log_file_name) - strlen(log_file_name) - 1);
+ memset(log_file_name, 0, length * sizeof(char));
+ strncat(log_file_name, name, length - strlen(log_file_name) - 1);
+ strncat(log_file_name, DLT_OFFLINETRACE_FILENAME_DELI,
+ length - strlen(log_file_name) - 1);
+ strncat(log_file_name, file_index, length - strlen(log_file_name) - 1);
+ strncat(log_file_name, DLT_OFFLINETRACE_FILENAME_EXT,
+ length - strlen(log_file_name) - 1);
}
unsigned int dlt_offline_trace_get_idx_of_log_file(char *file)
@@ -177,19 +180,17 @@ DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace)
{
time_t t;
struct tm tmp;
- char outstr[200];
- char newest[DLT_OFFLINETRACE_FILENAME_MAX_SIZE] = { 0 };
- char oldest[DLT_OFFLINETRACE_FILENAME_MAX_SIZE] = { 0 };
+ char outstr[NAME_MAX];
unsigned int idx = 0;
+ int ret = 0;
/* set filename */
if (trace->filenameTimestampBased) {
- int ret = 0;
t = time(NULL);
tzset();
localtime_r(&t, &tmp);
- strftime(outstr, sizeof(outstr), "%Y%m%d_%H%M%S", &tmp);
+ strftime(outstr, NAME_MAX, "%Y%m%d_%H%M%S", &tmp);
ret = snprintf(trace->filename, NAME_MAX, "%s/dlt_offlinetrace_%s.dlt", trace->directory, outstr);
@@ -199,12 +200,14 @@ DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace)
}
}
else {
- int ret = 0;
+ char newest[DLT_OFFLINETRACE_FILENAME_MAX_SIZE] = { 0 };
+ char oldest[DLT_OFFLINETRACE_FILENAME_MAX_SIZE] = { 0 };
/* targeting newest file, ignoring number of files in dir returned */
dlt_offline_trace_storage_dir_info(trace->directory, DLT_OFFLINETRACE_FILENAME_BASE, newest, oldest);
idx = dlt_offline_trace_get_idx_of_log_file(newest) + 1;
- dlt_offline_trace_file_name(outstr, DLT_OFFLINETRACE_FILENAME_BASE, idx);
+ dlt_offline_trace_file_name(outstr, NAME_MAX,
+ DLT_OFFLINETRACE_FILENAME_BASE, idx);
ret = snprintf(trace->filename, NAME_MAX, "%s/%s", trace->directory, outstr);
if ((ret < 0) || (ret >= NAME_MAX)) {