summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Brandner <simon.brandner@partner.bmw.de>2012-12-06 10:18:12 +0100
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-07-19 16:54:05 +0200
commitbe9c3bf964295883ff086dfb8c2ece38f833b355 (patch)
tree9faf2962efc5b7c24c98f5082d8afd4c2f7a2907
parent311b8896c144c5ff8c10dbc0d4c7832720292608 (diff)
downloadDLT-daemon-be9c3bf964295883ff086dfb8c2ece38f833b355.tar.gz
appended null termination to version string
adding closure of socket in syslog_thread and read_socket fixed missing free of filepath in compressed file transfer fixed missing closedir in added in send_one error case fixed missing fclose of src_file in ferror case dlt-daemon.c fixed missing fclose in ferror case dlt_common.c using snprintf for filename instead sprintf in dlt_file_open modified some magix numbers - replaced by limits.h values. added strncpy instead strcpy to make cp more safe. split up a function to avoid coverity complaint when computing size of a write buffer length dlt_daemon_common: added strncpy instead strcpy to make cp more safe. Fixes some more Coverity issues in dlt-daemon.c dlt_user.c dlt_common.c and dlt_offline_trace.c. Conflicts: src/daemon/dlt-daemon.c src/lib/dlt_user.c Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r--include/dlt/dlt_offline_trace.h6
-rw-r--r--src/daemon/dlt-daemon.c82
-rwxr-xr-xsrc/daemon/dlt-daemon.h14
-rw-r--r--src/daemon/dlt_daemon_common.c15
-rw-r--r--src/daemon/dlt_daemon_common.h7
-rw-r--r--src/lib/dlt_user.c28
-rwxr-xr-xsrc/shared/dlt_common.c15
-rw-r--r--src/shared/dlt_offline_trace.c9
-rw-r--r--src/system/dlt-system-filetransfer.c47
-rw-r--r--src/system/dlt-system-syslog.c5
10 files changed, 131 insertions, 97 deletions
diff --git a/include/dlt/dlt_offline_trace.h b/include/dlt/dlt_offline_trace.h
index 4b93719..0e7a356 100644
--- a/include/dlt/dlt_offline_trace.h
+++ b/include/dlt/dlt_offline_trace.h
@@ -53,10 +53,12 @@
#ifndef DLT_OFFLINE_TRACE_H
#define DLT_OFFLINE_TRACE_H
+#include <limits.h>
+
typedef struct
{
- char directory[256]; /**< (String) Store DLT messages to local directory */
- char filename[256]; /**< (String) Filename of currently used log file */
+ char directory[NAME_MAX + 1]; /**< (String) Store DLT messages to local directory */
+ char filename[NAME_MAX + 1]; /**< (String) Filename of currently used log file */
int fileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */
int maxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 7e9b6ba..059afe8 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -159,7 +159,7 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
}
case 'c':
{
- strncpy(daemon_local->flags.cvalue,optarg,sizeof(daemon_local->flags.cvalue));
+ strncpy(daemon_local->flags.cvalue,optarg,NAME_MAX);
break;
}
case 'h':
@@ -203,9 +203,10 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
int option_file_parser(DltDaemonLocal *daemon_local)
{
FILE * pFile;
- char line[1024];
- char token[1024];
- char value[1024];
+ int value_length = 1024;
+ char line[value_length-1];
+ char token[value_length];
+ char value[value_length];
char *pch;
const char *filename;
@@ -234,7 +235,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
while(1)
{
/* fetch line from configuration file */
- if ( fgets (line , 1024 , pFile) != NULL )
+ if ( fgets (line , value_length - 1 , pFile) != NULL )
{
pch = strtok (line," =\r\n");
token[0]=0;
@@ -247,11 +248,11 @@ int option_file_parser(DltDaemonLocal *daemon_local)
if(token[0]==0)
{
- strncpy(token,pch,sizeof(token));
+ strncpy(token,pch,sizeof(token) - 1);
}
else
{
- strncpy(value,pch,sizeof(value));
+ strncpy(value,pch,sizeof(value) - 1);
break;
}
@@ -308,22 +309,22 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
else if(strcmp(token,"RS232DeviceName")==0)
{
- strncpy(daemon_local->flags.yvalue,value,sizeof(daemon_local->flags.yvalue));
+ strncpy(daemon_local->flags.yvalue,value,NAME_MAX);
//printf("Option: %s=%s\n",token,value);
}
else if(strcmp(token,"RS232Baudrate")==0)
{
- strncpy(daemon_local->flags.bvalue,value,sizeof(daemon_local->flags.bvalue));
+ strncpy(daemon_local->flags.bvalue,value,NAME_MAX);
//printf("Option: %s=%s\n",token,value);
}
else if(strcmp(token,"ECUId")==0)
{
- strncpy(daemon_local->flags.evalue,value,sizeof(daemon_local->flags.evalue));
+ strncpy(daemon_local->flags.evalue,value,NAME_MAX);
//printf("Option: %s=%s\n",token,value);
}
else if(strcmp(token,"PersistanceStoragePath")==0)
{
- strncpy(daemon_local->flags.ivalue,value,sizeof(daemon_local->flags.ivalue));
+ strncpy(daemon_local->flags.ivalue,value,NAME_MAX);
//printf("Option: %s=%s\n",token,value);
}
else if(strcmp(token,"LoggingMode")==0)
@@ -338,7 +339,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
else if(strcmp(token,"LoggingFilename")==0)
{
- strncpy(daemon_local->flags.loggingFilename,value,sizeof(daemon_local->flags.loggingFilename));
+ strncpy(daemon_local->flags.loggingFilename,value,sizeof(daemon_local->flags.loggingFilename) - 1);
//printf("Option: %s=%s\n",token,value);
}
else if(strcmp(token,"SharedMemorySize")==0)
@@ -348,7 +349,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
else if(strcmp(token,"OfflineTraceDirectory")==0)
{
- strncpy(daemon_local->flags.offlineTraceDirectory,value,sizeof(daemon_local->flags.offlineTraceDirectory));
+ strncpy(daemon_local->flags.offlineTraceDirectory,value,sizeof(daemon_local->flags.offlineTraceDirectory) - 1);
//printf("Option: %s=%s\n",token,value);
}
else if(strcmp(token,"OfflineTraceFileSize")==0)
@@ -368,7 +369,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
else if(strcmp(token,"PathToECUSoftwareVersion")==0)
{
- strncpy(daemon_local->flags.pathToECUSoftwareVersion,value,sizeof(daemon_local->flags.pathToECUSoftwareVersion));
+ strncpy(daemon_local->flags.pathToECUSoftwareVersion,value,sizeof(daemon_local->flags.pathToECUSoftwareVersion) - 1);
//printf("Option: %s=%s\n",token,value);
}
@@ -995,25 +996,13 @@ void dlt_daemon_daemonize(int verbose)
/* Open standard descriptors stdin, stdout, stderr */
i=open("/dev/null",O_RDWR); /* open stdin */
ret=dup(i); /* stdout */
- if (0 > ret){
- dlt_log(LOG_CRIT, "can't open standard descriptor stdout\n");
- exit(-1); /* can not open */
- }
ret=dup(i); /* stderr */
- if (0 > ret){
- dlt_log(LOG_CRIT, "can't open standard descriptor stderr");
- exit(-1); /* can not open */
- }
/* Set umask */
umask(DLT_DAEMON_UMASK);
/* Change to known directory */
ret=chdir(DLT_USER_DIR);
- if (0 > ret){
- dlt_log(LOG_CRIT, "Can't change to known directory");
- exit(-1); /* Can't change to known directory */
- }
/* Ensure single copy of daemon;
run only one instance at a time */
@@ -1032,9 +1021,6 @@ void dlt_daemon_daemonize(int verbose)
sprintf(str,"%d\n",getpid());
bytes_written=write(lfp,str,strlen(str)); /* record pid to lockfile */
- if (0 > bytes_written){
- dlt_log(LOG_CRIT, "write pid to lockfile failed:");
- }
/* Catch signals */
signal(SIGCHLD,SIG_IGN); /* ignore child */
@@ -1932,21 +1918,24 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if (daemon_local->flags.lflag)
{
ret=write(j,dltSerialHeader,sizeof(dltSerialHeader));
- if (0 > ret)
+ if (0 > ret)
{
- dlt_log(LOG_ERR,"write(j,daemon_local->msg.headerbuffer failed\n");
+ dlt_log(LOG_ERR,"write(j,dltSerialHeader failed\n");
}
}
-
- ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader));
- if (0 > ret)
- {
- dlt_log(LOG_ERR,"write(j,dltSerialHeader failed\n");
- }
- ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize);
- if (0 > ret)
- {
- dlt_log(LOG_ERR,"write(j,daemon_local->msg.databuffer failed\n");
+ int32_t diff = daemon_local->msg.headersize-sizeof(DltStorageHeader);
+ //extra calculation for coverity
+ if ( 0 <= diff ){
+ ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),diff);
+ if (0 > ret)
+ {
+ dlt_log(LOG_ERR,"write(j,daemon_local->msg.headerbuffer failed\n");
+ }
+ ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize);
+ if (0 > ret)
+ {
+ dlt_log(LOG_ERR,"write(j,daemon_local->msg.databuffer failed\n");
+ }
}
DLT_DAEMON_SEM_FREE();
@@ -2443,14 +2432,18 @@ void dlt_daemon_ecu_version_thread(void *ptr)
while(!feof(f))
{
- char buf[DLT_DAEMON_TEXTBUFSIZE];
- read = fread(buf, 1, DLT_DAEMON_TEXTBUFSIZE, f);
+ char buf[DLT_DAEMON_TEXTBUFSIZE];
+ read = fread(buf, 1, DLT_DAEMON_TEXTBUFSIZE - 1, f);
+ buf [read] = '\0';//append null termination at end of version string. Read is definitely max: DLT_DAEMON_TEXTBUFSIZE - 1
+ read++;//Include the appended null termination position
+
if(ferror(f))
{
dlt_log(LOG_ERR, "Failed to read ECU Software version file.\n");
+ fclose(f);
return;
}
- if(bufpos + read > DLT_DAEMON_TEXTBUFSIZE)
+ if(bufpos + read > ( DLT_DAEMON_TEXTBUFSIZE - 1))
{
dlt_log(LOG_ERR, "Too long file for ecu version info.\n");
fclose(f);
@@ -2459,6 +2452,7 @@ void dlt_daemon_ecu_version_thread(void *ptr)
strncpy(version+bufpos, buf, read);
bufpos += read;
}
+ version[bufpos] = '\0';//append null termination at end of version string
fclose(f);
}
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index f595e8d..aa8c372 100755
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -65,12 +65,16 @@
#ifndef DLT_DAEMON_H
#define DLT_DAEMON_H
+#include <limits.h> /* for NAME_MAX */
+
#include "dlt_daemon_common.h"
#include "dlt_user_shared.h"
#include "dlt_user_shared_cfg.h"
+
#include <dlt_offline_trace.h>
+
/**
* The flags of a dlt daemon.
*/
@@ -85,11 +89,11 @@ typedef struct
int rflag; /**< (Boolean) Send automatic get log info response during context registration */
int mflag; /**< (Boolean) Sync to serial header on serial connection */
int nflag; /**< (Boolean) Sync to serial header on all TCP connections */
- char evalue[256]; /**< (String: ECU ID) Set ECU ID (Default: ECU1) */
- char bvalue[256]; /**< (String: Baudrate) Serial device baudrate (Default: 115200) */
- char yvalue[256]; /**< (String: Devicename) Additional support for serial device */
- char ivalue[256]; /**< (String: Directory) Directory where to store the persistant configuration (Default: /tmp) */
- char cvalue[256]; /**< (String: Directory) Filename of DLT configuration file (Default: /etc/dlt.conf) */
+ char evalue[NAME_MAX + 1]; /**< (String: ECU ID) Set ECU ID (Default: ECU1) */
+ char bvalue[NAME_MAX + 1]; /**< (String: Baudrate) Serial device baudrate (Default: 115200) */
+ char yvalue[NAME_MAX + 1]; /**< (String: Devicename) Additional support for serial device */
+ char ivalue[NAME_MAX + 1]; /**< (String: Directory) Directory where to store the persistant configuration (Default: /tmp) */
+ char cvalue[NAME_MAX + 1]; /**< (String: Directory) Filename of DLT configuration file (Default: /etc/dlt.conf) */
int sharedMemorySize; /**< (int) Size of shared memory (Default: 100000) */
int sendMessageTime; /**< (Boolean) Send periodic Message Time if client is connected (Default: 0) */
char offlineTraceDirectory[256]; /**< (String: Directory) Store DLT messages to local directory (Default: /etc/dlt.conf) */
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 7bbce7b..2f0e73a 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -125,6 +125,7 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
return -1;
}
+ int append_length = 0;
daemon->num_contexts = 0;
daemon->contexts = 0;
@@ -141,18 +142,24 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
daemon->mode = DLT_USER_MODE_EXTERNAL;
/* prepare filenames for configuration */
+
+ append_length = PATH_MAX - sizeof(DLT_RUNTIME_APPLICATION_CFG);
if(runtime_directory[0])
- strcpy(daemon->runtime_application_cfg,runtime_directory);
+ strncpy(daemon->runtime_application_cfg,runtime_directory,append_length);
else
strcpy(daemon->runtime_application_cfg,DLT_RUNTIME_DEFAULT_DIRECTORY);
strcat(daemon->runtime_application_cfg,DLT_RUNTIME_APPLICATION_CFG);
+
+ append_length = PATH_MAX - sizeof(DLT_RUNTIME_CONTEXT_CFG);
if(runtime_directory[0])
- strcpy(daemon->runtime_context_cfg,runtime_directory);
+ strncpy(daemon->runtime_context_cfg,runtime_directory,append_length);
else
strcpy(daemon->runtime_context_cfg,DLT_RUNTIME_DEFAULT_DIRECTORY);
strcat(daemon->runtime_context_cfg,DLT_RUNTIME_CONTEXT_CFG);
- if(runtime_directory[0])
- strcpy(daemon->runtime_configuration,runtime_directory);
+
+ append_length = PATH_MAX - sizeof(DLT_RUNTIME_CONFIGURATION);
+ if(runtime_directory[0])
+ strncpy(daemon->runtime_configuration,runtime_directory,append_length);
else
strcpy(daemon->runtime_configuration,DLT_RUNTIME_DEFAULT_DIRECTORY);
strcat(daemon->runtime_configuration,DLT_RUNTIME_CONFIGURATION);
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index b3dfbc6..8f5a36f 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -73,6 +73,7 @@
\{
*/
+#include <limits.h>
#include <semaphore.h>
#include "dlt_common.h"
#include "dlt_user.h"
@@ -137,9 +138,9 @@ typedef struct
int sendserialheader; /**< 1: send serial header; 0 don't send serial header */
int timingpackets; /**< 1: send continous timing packets; 0 don't send continous timing packets */
DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */
- char runtime_application_cfg[256]; /**< Path and filename of persistent application configuration */
- char runtime_context_cfg[256]; /**< Path and filename of persistent context configuration */
- char runtime_configuration[256]; /**< Path and filename of persistent configuration */
+ char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to path max, as it specifies a full path*/
+ char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */
+ char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */
DltUserLogMode mode; /**< Mode used for tracing: off, external, internal, both */
char state; /**< state for tracing: 0 = no client connected, 1 = client connected */
} DltDaemon;
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 8155d52..9c40a30 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -2109,14 +2109,14 @@ int dlt_user_trace_network_segmented_end(uint16_t id, DltContext *handle, DltNet
void dlt_user_trace_network_segmented_thread(void *unused)
{
- /* Unused on purpose. */
- (void) unused;
+ /* Unused on purpose. */
+ (void) unused;
- s_segmented_data *data;
+ s_segmented_data *data;
while(1)
{
- // Wait untill message queue is initialized
+ // Wait until message queue is initialized
pthread_mutex_lock(&mq_mutex);
if(dlt_user.dlt_segmented_queue_read_handle < 0)
{
@@ -2241,10 +2241,10 @@ int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_
thread_data->payload_len);
if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
{
- dlt_log(LOG_ERR,"NWTSegmented: Could not send start segment. Aborting.\n");
- free(thread_data->header);
- free(thread_data->payload);
- free(thread_data);
+ dlt_log(LOG_ERR,"NWTSegmented: Could not send start segment. Aborting.\n");
+ free(thread_data->header);
+ free(thread_data->payload);
+ free(thread_data);
return -1;
}
@@ -2274,6 +2274,9 @@ int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_
dlt_log(LOG_ERR, strerror(errno));
return -1;
}
+
+ //thread_data will be freed by the receiver function
+ //coverity[leaked_storage]
return 0;
}
@@ -2701,7 +2704,7 @@ int dlt_user_queue_resend(void)
if(dlt_init_message_queue() < 0)
{
dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
- free(resend_data);
+ free(resend_data);
return -1;
}
@@ -2713,6 +2716,8 @@ int dlt_user_queue_resend(void)
DLT_SEM_FREE();
return -1;
}
+ //thread_data will be freed by the receiver function
+ //coverity[leaked_storage]
return 0;
}
@@ -3492,7 +3497,10 @@ int dlt_user_log_check_user_message(void)
/* Delayed injection callback call */
if(delayed_inject_buffer != 0 && delayed_injection_callback.injection_callback != 0) {
delayed_injection_callback.injection_callback(delayed_injection_callback.service_id, delayed_inject_buffer, delayed_inject_data_length);
- free(delayed_inject_buffer);
+ delayed_injection_callback.injection_callback = 0;
+ free(delayed_inject_buffer);
+ delayed_inject_buffer = NULL;
+
}
/* keep not read data in buffer */
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 68d06c6..b2324b1 100755
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -67,6 +67,7 @@
#include <stdlib.h> /* for malloc(), free() */
#include <string.h> /* for strlen(), memcmp(), memmove() */
#include <time.h> /* for localtime(), strftime() */
+#include <limits.h> /* for NAME_MAX */
#include "dlt_common.h"
#include "dlt_common_cfg.h"
@@ -102,7 +103,7 @@ char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D','L','S',1 };
/* internal logging parameters */
static int logging_mode = 0;
static int logging_level = 6;
-static char logging_filename[256] = "";
+static char logging_filename[NAME_MAX + 1] = "";
static FILE *logging_handle = 0;
char *message_type[] = {"log","app_trace","nw_trace","control","","","",""};
@@ -583,8 +584,10 @@ int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int ver
/* apid matches, now check for ctid */
if (ctid==0)
{
- /* check if empty ctid matches */
- if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)
+ /* check if empty ctid matches */
+ //if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)//coverity complains here about Out-of-bounds access.
+ char empty_ctid[DLT_ID_SIZE]="";
+ if (memcmp(filter->ctid[num],empty_ctid,DLT_ID_SIZE)==0)
{
return num;
}
@@ -1654,7 +1657,8 @@ int dlt_file_open(DltFile *file,const char *filename,int verbose)
file->handle = fopen(filename,"rb");
if (file->handle == 0)
{
- sprintf(str,"File %s cannot be opened!\n",filename);
+ snprintf(str, DLT_COMMON_BUFFER_LENGTH - 1 ,"File %s cannot be opened!\n",filename);
+
dlt_log(LOG_ERR, str);
return -1;
}
@@ -1967,7 +1971,8 @@ void dlt_log_set_level(int level)
void dlt_log_set_filename(const char *filename)
{
- strncpy(logging_filename,filename,sizeof(logging_filename));
+ strncpy(logging_filename,filename,NAME_MAX);
+
}
void dlt_log_init(int mode)
diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c
index 206fa51..72b31ad 100644
--- a/src/shared/dlt_offline_trace.c
+++ b/src/shared/dlt_offline_trace.c
@@ -170,7 +170,7 @@ int dlt_offline_trace_check_size(DltOfflineTrace *trace) {
int dlt_offline_trace_init(DltOfflineTrace *trace,const char *directory,int fileSize,int maxSize) {
/* init parameters */
- strcpy(trace->directory,directory);
+ strncpy(trace->directory,directory,NAME_MAX);
trace->fileSize = fileSize;
trace->maxSize = maxSize;
@@ -190,6 +190,7 @@ int dlt_offline_trace_write(DltOfflineTrace *trace,unsigned char *data1,int size
{
/* close old file */
close(trace->ohandle);
+ trace->ohandle = -1;
/* check complete offline trace size, remove old logs if needed */
dlt_offline_trace_check_size(trace);
@@ -199,19 +200,19 @@ int dlt_offline_trace_write(DltOfflineTrace *trace,unsigned char *data1,int size
}
/* write data into log file */
- if(data1) {
+ if(data1 && (trace->ohandle >= 0)) {
if(write(trace->ohandle,data1,size1)!=size1) {
printf("Offline trace write failed!\n");
return -1;
}
}
- if(data2) {
+ if(data2 && (trace->ohandle >= 0)) {
if(write(trace->ohandle,data2,size2)!=size2) {
printf("Offline trace write failed!\n");
return -1;
}
}
- if(data3) {
+ if(data3 && (trace->ohandle >= 0)) {
if(write(trace->ohandle,data3,size3)!=size3) {
printf("Offline trace write failed!\n");
return -1;
diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c
index 93a8cf3..aeee540 100644
--- a/src/system/dlt-system-filetransfer.c
+++ b/src/system/dlt-system-filetransfer.c
@@ -128,6 +128,7 @@ char *compress_file(char *src, int level)
free(buf);
free(dst);
gzclose(dst_file);
+ fclose(src_file);
return NULL;
}
gzwrite(dst_file, buf, read);
@@ -151,6 +152,7 @@ int send_one(char *src, FiletransferOptions opts, int which)
char *fn = basename(src);
char *rn = unique_name(src);
char *dst = malloc(strlen(opts.TempDir)+strlen(rn)+2);
+ char *dst_tmp = NULL;
MALLOC_ASSERT(fn);
MALLOC_ASSERT(rn);
MALLOC_ASSERT(dst);
@@ -170,35 +172,37 @@ int send_one(char *src, FiletransferOptions opts, int which)
// Compress if needed
if(opts.Compression[which] > 0)
{
- dst = compress_file(dst, opts.CompressionLevel[which]);
+ dst_tmp = dst;
+ dst = compress_file(dst_tmp, opts.CompressionLevel[which]);
+ free(dst_tmp);//no more used
char *old_fn = fn;
fn = malloc(strlen(old_fn)+4);
MALLOC_ASSERT(fn);
sprintf(fn, "%s.gz", old_fn);
}
- if(dlt_user_log_file_header_alias(&filetransferContext, dst, fn) == 0)
+ if(dlt_user_log_file_header_alias(&filetransferContext, dst, fn) == 0)
{
- int pkgcount = dlt_user_log_file_packagesCount(&filetransferContext, dst);
+ int pkgcount = dlt_user_log_file_packagesCount(&filetransferContext, dst);
int lastpkg = 0;
while(lastpkg < pkgcount)
- {
- int total = 2;
- int used = 2;
- dlt_user_check_buffer(&total, &used);
- while((total-used) < (total/2))
- {
- struct timespec t;
- t.tv_sec = 0;
- t.tv_nsec = 1000000ul*opts.TimeoutBetweenLogs;
- nanosleep(&t, NULL);
- dlt_user_check_buffer(&total, &used);
- }
- lastpkg++;
- if(dlt_user_log_file_data(&filetransferContext, dst, lastpkg, opts.TimeoutBetweenLogs) < 0)
- break;
- }
- dlt_user_log_file_end(&filetransferContext, dst, 1);
+ {
+ int total = 2;
+ int used = 2;
+ dlt_user_check_buffer(&total, &used);
+ while((total-used) < (total/2))
+ {
+ struct timespec t;
+ t.tv_sec = 0;
+ t.tv_nsec = 1000000ul*opts.TimeoutBetweenLogs;
+ nanosleep(&t, NULL);
+ dlt_user_check_buffer(&total, &used);
+ }
+ lastpkg++;
+ if(dlt_user_log_file_data(&filetransferContext, dst, lastpkg, opts.TimeoutBetweenLogs) < 0)
+ break;
+ }
+ dlt_user_log_file_end(&filetransferContext, dst, 1);
}
if(opts.Compression[which] > 0)
@@ -230,7 +234,10 @@ int flush_dir(FiletransferOptions opts, int which)
MALLOC_ASSERT(fn);
sprintf(fn, "%s/%s", sdir, dp->d_name);
if(send_one(fn, opts, which) < 0)
+ {
+ closedir(dir);
return -1;
+ }
}
}
else
diff --git a/src/system/dlt-system-syslog.c b/src/system/dlt-system-syslog.c
index b07e6d6..c788d94 100644
--- a/src/system/dlt-system-syslog.c
+++ b/src/system/dlt-system-syslog.c
@@ -84,6 +84,7 @@ int init_socket(SyslogOptions opts)
{
DLT_LOG(syslogContext, DLT_LOG_FATAL,
DLT_STRING("Unable to bind socket for SYSLOG."));
+ close(sock);
return -1;
}
@@ -138,8 +139,12 @@ void syslog_thread(void *v_conf)
while(!threads.shutdown)
{
if(read_socket(sock) < 0)
+ {
+ close(sock);
return;
+ }
}
+ close (sock);
}
void start_syslog(DltSystemConfiguration *conf)