diff options
author | Dinh Cong Toan <toan.dinhcong@vn.bosch.com> | 2020-12-01 15:02:27 +0700 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2021-01-06 09:27:28 +0900 |
commit | 929a02f18556b9f1109c84d784a56de1e36a6e41 (patch) | |
tree | 3df54d2f67cdaa9c7581fd0fd285f9abb63c1f64 /src/shared | |
parent | 6f4d05fe7c2a90b3e89837cbea9cac95c09ad746 (diff) | |
download | DLT-daemon-929a02f18556b9f1109c84d784a56de1e36a6e41.tar.gz |
gtest_dlt_common: fix seg fault when using memcpy().
- Checking size of buffer and size of message before using memcpy().
- Adding configuration file for testfilter in /tests/CMakeLists.txt.
Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/dlt_common.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 1ae56c1..f8aa746 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2392,9 +2392,11 @@ void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *dat *write += (int) size; } else { - /* write two blocks */ - memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write)); - memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write)); + if(buf->size > (unsigned int) (*write)) { + /* write two blocks */ + memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write)); + memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write)); + } *write += (int) (size - buf->size); } } @@ -2417,9 +2419,11 @@ void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsig *read +=(int) size; } else { + if(buf->size > (unsigned int) (*read)) { /* read two blocks */ - memcpy(data, buf->mem + *read, buf->size - (unsigned int) (*read)); - memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int) (*read)); + memcpy(data, buf->mem + *read, buf->size - (unsigned int) (*read)); + memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int) (*read)); + } *read += (int) (size - buf->size); } } |