From 5909561a7ac82ba25694321f3ffa37c83f7e085f Mon Sep 17 00:00:00 2001 From: Lassi Marttala Date: Tue, 21 Feb 2012 13:02:16 +0100 Subject: GENDLT-15, Safe re-allocations for databuffer. Signed-off-by: Christian Muck --- src/daemon/dlt-daemon.c | 8 ++++++-- src/daemon/dlt_daemon_common.c | 34 ++++++++++++++++++++++++++-------- src/lib/dlt_client.c | 8 ++++++-- src/lib/dlt_user.c | 13 ++++++++----- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 79d8bea..04612bb 100755 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1527,11 +1527,15 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemo } msg.datasize = sizeof(DltServiceGetLogInfoRequest); - if (msg.databuffer) + if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); + msg.databuffer=0; + } + if (msg.databuffer == 0){ + msg.databuffer = (uint8_t *) malloc(msg.datasize); + msg.databuffersize = msg.datasize; } - msg.databuffer = (uint8_t *) malloc(msg.datasize); if (msg.databuffer==0) { dlt_log(LOG_ERR,"Can't allocate buffer for get log info message\n"); diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index 0eaff98..2e3cc75 100755 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -1488,11 +1488,15 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int ve len = strlen(version); msg.datasize = sizeof(DltServiceGetSoftwareVersionResponse) + len; - if (msg.databuffer) + if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); + msg.databuffer=0; + } + if (msg.databuffer == 0){ + msg.databuffer = (uint8_t *) malloc(msg.datasize); + msg.databuffersize = msg.datasize; } - msg.databuffer = (uint8_t *) malloc(msg.datasize); if (msg.databuffer==0) { dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); @@ -1532,11 +1536,15 @@ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, int v } msg.datasize = sizeof(DltServiceGetDefaultLogLevelResponse); - if (msg.databuffer) + if (msg.databuffer && (msg.databuffersize