diff options
author | Lassi Marttala <lassi.lm.marttala@partner.bmw.com> | 2012-02-21 13:02:16 +0100 |
---|---|---|
committer | Christian Muck <christian.muck@bmw.de> | 2012-04-04 14:30:43 +0200 |
commit | 5909561a7ac82ba25694321f3ffa37c83f7e085f (patch) | |
tree | ba7c99792490570dc3a367600a4ad7fba79e6876 /src/daemon | |
parent | aea3ecd7cbbdff54dc061357e96cf606f9a52dea (diff) | |
download | DLT-daemon-5909561a7ac82ba25694321f3ffa37c83f7e085f.tar.gz |
GENDLT-15, Safe re-allocations for databuffer.
Signed-off-by: Christian Muck <christian.muck@bmw.de>
Diffstat (limited to 'src/daemon')
-rwxr-xr-x | src/daemon/dlt-daemon.c | 8 | ||||
-rwxr-xr-x | src/daemon/dlt_daemon_common.c | 34 |
2 files changed, 32 insertions, 10 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<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_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); @@ -1745,6 +1753,8 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *ms /* Allocate buffer for response message */ resp.databuffer = (uint8_t *) malloc(resp.datasize); + resp.databuffersize = resp.datasize; + if (resp.databuffer==0) { dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); @@ -1956,11 +1966,15 @@ void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int /* prepare payload of data */ msg.datasize = sizeof(DltServiceMessageBufferOverflowResponse); - 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) { if (sock!=DLT_DAEMON_STORE_TO_BUFFER) @@ -2002,11 +2016,15 @@ void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, uint32_t /* prepare payload of data */ msg.datasize = sizeof(DltServiceResponse); - 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) { return; |