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_common.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/daemon/dlt_daemon_common.c') 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