summaryrefslogtreecommitdiff
path: root/src/system
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 /src/system
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>
Diffstat (limited to 'src/system')
-rw-r--r--src/system/dlt-system-filetransfer.c47
-rw-r--r--src/system/dlt-system-syslog.c5
2 files changed, 32 insertions, 20 deletions
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)