diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2013-12-06 08:10:14 +0100 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-01-10 07:15:57 +0100 |
commit | f32a86f4ff92cd40005807488ad4281ba6958bf1 (patch) | |
tree | fbcc51579a5c2978d994a85dde59906a5c7d52b0 /src | |
parent | 216ab4260fa05795564766ab3ea0f3020d036fd3 (diff) | |
download | DLT-daemon-f32a86f4ff92cd40005807488ad4281ba6958bf1.tar.gz |
Fixed possible crash when runtime configurations files are corrupted.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/dlt_daemon_common.c | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index d47aafa..bbd058d 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -483,6 +483,9 @@ int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int ver if (fd==0) { + snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "DLT runtime-application load, cannot open file %s: %s\n", filename, strerror(errno)); + dlt_log(LOG_WARNING, str); + return -1; } @@ -522,15 +525,21 @@ int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int ver { /* Split line */ pb=strtok(buf,":"); - dlt_set_id(apid,pb); - pb=strtok(NULL,":"); - /* pb contains now the description */ - - /* pid is unknown at loading time */ - if (dlt_daemon_application_add(daemon,apid,0,pb,verbose)==0) + if( pb != 0 ) { - fclose(fd); - return -1; + dlt_set_id(apid,pb); + pb=strtok(NULL,":"); + if( pb != 0 ) + { + /* pb contains now the description */ + /* pid is unknown at loading time */ + if (dlt_daemon_application_add(daemon,apid,0,pb,verbose)==0) + { + dlt_log(LOG_ERR, "dlt_daemon_applications_load dlt_daemon_application_add failed\n"); + fclose(fd); + return -1; + } + } } } } @@ -846,6 +855,9 @@ int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose if (fd==0) { + snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "DLT runtime-context load, cannot open file %s: %s\n", filename, strerror(errno)); + dlt_log(LOG_WARNING, str); + return -1; } @@ -885,21 +897,37 @@ int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose { /* Split line */ pb=strtok(buf,":"); - dlt_set_id(apid,pb); - pb=strtok(NULL,":"); - dlt_set_id(ctid,pb); - pb=strtok(NULL,":"); - sscanf(pb,"%d",&ll); - pb=strtok(NULL,":"); - sscanf(pb,"%d",&ts); - pb=strtok(NULL,":"); - /* pb contains now the description */ - - /* log_level_pos, and user_handle are unknown at loading time */ - if (dlt_daemon_context_add(daemon,apid,ctid,(int8_t)ll,(int8_t)ts,0,0,pb,verbose)==0) + if(pb!=0) { - fclose(fd); - return -1; + dlt_set_id(apid,pb); + pb=strtok(NULL,":"); + if(pb!=0) + { + dlt_set_id(ctid,pb); + pb=strtok(NULL,":"); + if(pb!=0) + { + sscanf(pb,"%d",&ll); + pb=strtok(NULL,":"); + if(pb!=0) + { + sscanf(pb,"%d",&ts); + pb=strtok(NULL,":"); + if(pb!=0) + { + /* pb contains now the description */ + + /* log_level_pos, and user_handle are unknown at loading time */ + if (dlt_daemon_context_add(daemon,apid,ctid,(int8_t)ll,(int8_t)ts,0,0,pb,verbose)==0) + { + dlt_log(LOG_ERR, "dlt_daemon_contexts_load dlt_daemon_context_add failed\n"); + fclose(fd); + return -1; + } + } + } + } + } } } } |