From 64646a665c9fafc4454c67b6212702ed59e01c87 Mon Sep 17 00:00:00 2001 From: Lassi Marttala Date: Tue, 21 Feb 2012 12:16:23 +0100 Subject: GENDLT-15, Avoid buffer overrun with snprintf(). Check return value of dlt_user_log_write_start(_id) correctly. Reduce the number of applications if allocation fails. Make dlt_user_log_write_start inline Improve error checking in dlt_user_log_write_start_id Use databuffersize to avoid reallocations Signed-off-by: Christian Muck --- src/examples/dlt-example-user-func.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/examples') diff --git a/src/examples/dlt-example-user-func.c b/src/examples/dlt-example-user-func.c index e716335..75db1b0 100755 --- a/src/examples/dlt-example-user-func.c +++ b/src/examples/dlt-example-user-func.c @@ -240,28 +240,28 @@ int main(int argc, char* argv[]) if (gflag) { /* DLT messages to test Fibex non-verbose description: dlt-example-non-verbose.xml */ - if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,10)) + if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,10)>0) { dlt_user_log_write_finish(&mycontextdata); } - if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,11)) + if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,11)>0) { dlt_user_log_write_uint16(&mycontextdata,1011); dlt_user_log_write_finish(&mycontextdata); } - if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,12)) + if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,12)>0) { dlt_user_log_write_uint32(&mycontextdata,1012); dlt_user_log_write_uint32(&mycontextdata,1013); dlt_user_log_write_finish(&mycontextdata); } - if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,13)) + if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,13)>0) { dlt_user_log_write_uint8(&mycontextdata,123); dlt_user_log_write_float32(&mycontextdata,1.12); dlt_user_log_write_finish(&mycontextdata); } - if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,14)) + if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_INFO,14)>0) { dlt_user_log_write_string(&mycontextdata,"DEAD BEEF"); dlt_user_log_write_finish(&mycontextdata); @@ -275,7 +275,7 @@ int main(int argc, char* argv[]) if (gflag) { /* Non-verbose mode */ - if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_WARN,num)) + if (dlt_user_log_write_start_id(&mycontext,&mycontextdata,DLT_LOG_WARN,num)>0) { dlt_user_log_write_int(&mycontextdata,num); dlt_user_log_write_string(&mycontextdata,text); @@ -285,7 +285,7 @@ int main(int argc, char* argv[]) else { /* Verbose mode */ - if (dlt_user_log_write_start(&mycontext,&mycontextdata,DLT_LOG_WARN)) + if (dlt_user_log_write_start(&mycontext,&mycontextdata,DLT_LOG_WARN)>0) { dlt_user_log_write_int(&mycontextdata,num); dlt_user_log_write_string(&mycontextdata,text); -- cgit v1.2.1